The “cumprod” Function in R

  • Package: Base R (No specific package, it’s a built-in function)

  • Purpose: To compute the cumulative product of a numeric vector.

  • General Class: Mathematical Computation

  • Required Argument(s):

    • x: A numeric vector for which the cumulative product is to be computed.

  • Notable Optional Arguments:

    • None

  • Example:

  • # Example usage
    my_vector <- c(2, 3, 1, 4, 5)
    cumulative_product <- cumprod(my_vector)

    print(cumulative_product)

  • In this example, cumprod is a built-in function in base R, and it is used to calculate the cumulative product of a numeric vector. The x argument is the only required argument, and it represents the numeric vector for which the cumulative product is calculated. There are no notable optional arguments for this function. The result is a numeric vector where each element represents the cumulative product up to that point in the input vector.

Previous
Previous

The “cummin” Function in R

Next
Next

The “cumsum” Function in R