r - package or function to count sequence lengths? -


i wondering if there package or generic function in r counts sequence lengths. instance, if input sequence

s1<-c('a','a','b','a','a','a','b','b')

the proposed function f(s1,'a') return vector: [2,3] , f(s1,'b') return [1,2]

those madly typing people must have gone elsewhere:

 s1<- c('a','a','b','a','a','a','b','b')  f1 <- function(s, el) {rle(s)$lengths[rle(s)$values==el] }  f1(s1, "a") #[1] 2 3  f1(s1, "b") #[1] 1 2 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -