df <- data.frame(Semester = c(rep(1, each=8), rep(2, each=6), rep(3, each=5)))
I want to make a second column, Student
, that for every semester, goes 1, 2, 3,... and then resets for the next semester. That is, it creates the following:
df <- data.frame(Semester = c(rep(1, each=8), rep(2, each=6), rep(3, each=5)),
Student = c(1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5))
just from the Semester
column. How do I do this without a for
loop?