I'm trying to repeat the sequence 0, 1, 2 down the rows of my data frame with the following:
x <- c(1, 2, 3, 4, 5, 6, 7)
y <- c(1, 2, 3, 4, 5, 6, 7)
df <- cbind(x, y)
df <- as.data.frame(df)
df$W <- rep(0:2, nrow(df)/3)
df$W <- rep(0:1, nrow(df)/2)
Which doesn't work because the replacement has 6 rows, data has 7. I feel like there has to be a simpler solution to this. I just want it start the next sequence but stop when it finishes at the last row of the data frame. So W would just be 0, 1, 2, 0, 1, 2, 0. And for the other option with rep(0:1) it would be 0, 1, 0, 1, 0, 1, 0