Calculate the Cumulative Minima of a Vector in R Programming – cummin() Function
Last Updated :
15 Jun, 2020
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:
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:
x1 < - c( 3 , 6 , 4 , 2 , 6 , 7 )
x2 < - c( - 4 , 6 , 3 )
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.
Share your thoughts in the comments
Please Login to comment...