library(dplyr)
library(zoo)
x<-c(0,0,1,1,0,1,1,1,0,1,1,0,1,1)
aaa<-data.frame(x)
a <- tbl_df(aaa) %>%
mutate(id = (1:length(x)))
b <- a %>%
filter(x == 0) %>%
mutate(id2 = (1:length(x))) %>%
mutate(check = ifelse(as.integer(id2 / 2) == id2 / 2, F, T)) %>%
select(-id2)
out <- a %>%
full_join(b) %>%
na.locf() %>%
mutate(ref = ifelse(check, as.character(id), ''))


雷达卡


京公网安备 11010802022788号







