Hi
it would be cool to have data.table::rleid in dplyr for grouping, window functions etc.
http://stackoverflow.com/questions/33507868/is-there-a-dplyr-equivalent-to-data-tablerleid
myrleid <- function(x) {
x <- rle(x)$lengths
rep(seq_along(x), times=x)
}
DT <- data.frame(grp=rep(c("A", "B", "C", "A", "B"), c(2,2,3,1,2)), value=1:10)
DT %<>% mutate(rlid = myrleid(grp))
DT
Greetings
Christof
Hi
it would be cool to have data.table::rleid in dplyr for grouping, window functions etc.
http://stackoverflow.com/questions/33507868/is-there-a-dplyr-equivalent-to-data-tablerleid
myrleid <- function(x) {
x <- rle(x)$lengths
rep(seq_along(x), times=x)
}
DT <- data.frame(grp=rep(c("A", "B", "C", "A", "B"), c(2,2,3,1,2)), value=1:10)
DT %<>% mutate(rlid = myrleid(grp))
DT
Greetings
Christof