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
Post a Comment