Calculate the Cumulative Minima of a Vector in R Programming – cummin() Function
cummin()
function in R Language is used to calculate the cumulative minima of the values of vector passed as arguments.
Syntax: cummin(x)
Parameters:
x: numeric object
Example 1:
# R program to cumulative minima # Calling cummin() function cummin( 2 : 6 ) cummin( - 2 : - 6 ) cummin( 1.8 : 4.2 ) |
Output:
[1] 2 2 2 2 2 [1] -2 -3 -4 -5 -6 [1] 1.8 1.8 1.8
Example 2:
# R program to cumulative minima # Creating vectors x1 < - c( 3 , 6 , 4 , 2 , 6 , 7 ) x2 < - c( - 4 , 6 , 3 ) # Calling cummin() function cummin(x1) cummin(x2) |
Output:
[1] 3 3 3 2 2 2 [1] -4 -4 -4
Since, the minima is calculated for the values in increasing order and hence the above code shows two cumulative values for first vector.
Contact Us