![]() |
VOOZH | about |
In this article, we will see how to find the product of vector elements in R programming language.
Approach
The following code snippet indicates the application of for loop over decimal point vector. The product obtained is also of the decimal type.
Example:
Output
[1] "Product of vector elements:"
[1] 28.16
The other example demonstrates the behavior of any mathematical operation on a missing, that is NA value. The product returned is NA, in such a case.
Example 2:
Output
Product after iteration:[1] 1.1
Product after iteration:[1] 2.2
Product after iteration:[1] NA
Product after iteration:[1] NA
Product after iteration:[1] NA
[1] "Final product of vector elements:"
[1] NA
prod() function in R is an in-built method which can directly compute the multiplicative product of the individual elements in the vector which are specified as its arguments. In case, a single argument is present, it computes the multiplicative output of the individual elements of the vector.
Syntax:
prod(vector)
Example:
Output
[1] "Product of vector elements:"
[1] 24