I would like to take a data set like this:
dat <- data.frame(pos = 1:120, state = c(rep("state1", 30), rep("state2",30), rep("state3",30), rep("state1", 30)))
And collapse it into this form:
dat2 <- data.frame(start = seq(1,120,30), end = seq(30,120,30), state = c("state1","state2","state3","state1"))
In summary, I want to know the begining and end of each category as they appear in the data.