I'm struggling to solve a seemingly simple task. In this type of data:
df <- data.frame(
A = c(1,2,3,4,1,2,3,2,2,2,2,1,1,1,1,6,7)
)
I want to add an id variable that groups column A by a regular interval, say, of 5. An additional difficulty is that the number of rows is 17, thus not a multiple of 5:
df <- data.frame(
A = c(1,2,3,4,1,2,3,2,2,2,2,1,1,1,1,6,7),
id = c("a","a","a","a","a",
"b","b","b","b","b",
"c","c","c","c","c",
"d","d"))
How can this be done?
