要获得可以使用的范围 rle
首先创建编码
x <- c(5,5,6,6,7,5,4,4,4,3,2,1,1,1,2,3,4,5,6,7,6,5,4,3,2,2,3,4,4)
enc <- rle(x <= 3)
enc.endidx <- cumsum(enc$lengths) #ending indices
enc.startidx <- c(0, enc.endidx[1:(length(enc.endidx)-1)]) + 1 # starting indices
data.frame(startidx=enc.startidx[enc$values], endidx=enc.endidx[enc$values])
Run Code Online (Sandbox Code Playgroud)
那应该给你
startidx endidx
1 10 16
2 24 27
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
478 次 |
| 最近记录: |