Last active
January 21, 2018 18:44
-
-
Save tbobin/f7c2703e478f5b39a4c4daaa53eafc06 to your computer and use it in GitHub Desktop.
rolling count repeating 1 in column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
dates <- c("2017-10-30", | |
"2017-11-06", | |
"2017-11-14", | |
"2017-11-20", | |
"2017-11-27", | |
"2017-12-04", | |
"2017-12-11", | |
"2017-12-18", | |
"2018-01-08") | |
waiting <- c(0, 1, 1, 0, 0, 0, 1, 1, 1) | |
df <- data.frame(dates = as.Date(dates), waiting = waiting) | |
df %>% mutate(c_sum = sequence(rle(waiting)$lengths)*waiting) | |
# repeating same conneced values | |
a <- rle(waiting) | |
sequence(a$lengths) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment