Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一个向量
x<-c(1,2,3,4,5,6,7,0,0,1,2,3,0,0,0,3,0,1)
我想知道向量中的值连续非零的时间。对于这种情况,我想得到 7、3、1、1 的含义。
我怎样才能做到这一点?
一种选择可能是:
with(rle(x != 0), lengths[values]) [1] 7 3 1 1