param等于0时向量中的拉伸次数
The number of stretches in the vector when the param is equal to 0
当 param
等于 0 时,如何找到向量中的拉伸(块)数?在这个例子中,答案是 3.
向量param
:
param <- c(25, 20, 18, 5, 1, 0, 0, 0, 1, 5, 0, 0, 3, 6, 9, 0, 0)
我假设 "stretch" 至少有两个或更多值。但是有了你的测试数据
x<- c(25, 20, 18, 5, 1, 0, 0, 0, 1, 5, 0, 0, 3, 6, 9, 0, 0)
我会使用 rle()
函数来计算 运行 长度
with(rle(x), sum(values==0 & lengths>1))
# [1] 3
当 param
等于 0 时,如何找到向量中的拉伸(块)数?在这个例子中,答案是 3.
向量param
:
param <- c(25, 20, 18, 5, 1, 0, 0, 0, 1, 5, 0, 0, 3, 6, 9, 0, 0)
我假设 "stretch" 至少有两个或更多值。但是有了你的测试数据
x<- c(25, 20, 18, 5, 1, 0, 0, 0, 1, 5, 0, 0, 3, 6, 9, 0, 0)
我会使用 rle()
函数来计算 运行 长度
with(rle(x), sum(values==0 & lengths>1))
# [1] 3