2015-11-05 90 views

回答

1

這是我使用的答案:我想要計算一個和零個字符串的數量,並使用下面的代碼。

out.full <- within(df, { 
smaller <- unlist(lapply(split(var1, var2), function(x) sequence(rle(x)$lengths))) 
cum.ones <- replace(smaller, var1 == 1,NA) 
cum.zeroes <- replace(smaller, var1 == 0, NA) 
rm(smaller) 
})