在R编程中计算向量的累积最大值– cummax()函数用法介绍

2021年3月17日14:13:53 发表评论 1,252 次浏览

cummax()发挥作用:R语言用于计算作为参数传递的向量的值的累积最大值。

语法:cummax(x)参数:x:数字对象

范例1:

# R program to cumulative maxima
  
# Calling cummax() function
cummax( 6 : 2 )
cummax( - 2 : - 6 )
cummax( 3.8 : 1.2 )

输出如下:

[1] 6 6 6 6 6
[1] -2 -2 -2 -2 -2
[1] 3.8 3.8 3.8

范例2:

# R program to cumulative maxima
  
# Creating vectors
x1 < - c( 5 , 3 , 2 , 6 , 3 , 4 )
x2 < - c( - 4 , 6 , 3 )
  
# Calling cummax() function
cummax(x1)
cummax(x2)

输出如下:

[1] 5 5 5 6 6 6
[1] -4  6  6

由于最大值是按降序计算的, 因此上述代码显示了向量的两个累加值。


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: