Find longest run of consecutive zeros for each user in dataframe
问题 I'm looking to find the max run of consecutive zeros in a DataFrame with the result grouped by user. I'm interested in running the RLE on usage. sample input: user--day--usage A-----1------0 A-----2------0 A-----3------1 B-----1------0 B-----2------1 B-----3------0 Desired output user---longest_run a - - - - 2 b - - - - 1 mydata <- mydata[order(mydata$user, mydata$day),] user <- unique(mydata$user) d2 <- data.frame(matrix(NA, ncol = 2, nrow = length(user))) names(d2) <- c("user", "longest_no