Getting Multiplication of the Objects passed as Arguments in R Language – prod() Function

prod() function in R Language is used to return the multiplication results of all the values present in its arguments.

Syntax: prod(…)

Parameters:
…: numeric or complex or logical vectors

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# prod function
  
# Initializing some vectors of element
x <- c(1, 2, 3, 4)
y <- c(0, 2, 4, 6)
z <- c(2.6, 3.7, 1.9)
  
# Calling the prod() function
prod(x) # 1 × 2 × 3 × 4 
prod(y)
prod(z)

chevron_right


Output:

[1] 24
[1] 0
[1] 18.278

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to illustrate
# prod function
  
# Calling the prod() function
prod(1:3) # 1 × 2 × 3
prod(0:8)
prod(2:6)

chevron_right


Output:

[1] 6
[1] 0
[1] 720
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.