This sounds simple, but having a hard time figuring it out. I have a dataframe (S) with one column populated with numeric months (1-12 i.e Jan-Dec):
S$month
[1] 6 7 12 1 2 3 4 5 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10
[27] 11 12 2 3 4 6 10 11 12 1 2 3 5 6 7 7
I'd like to split the dataframe into a list as such consecutive months are grouped as shown below:
S[[1]]$month
[1] 6 7
S[[2]]$month
[1] 12 1 2 3 4 5 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10
[25] 11 12
S[[3]]$month
[1] 2 3 4
S[[4]]$month
[1] 6
S[[5]]$month
[1] 10 11 12 1 2 3
S[[6]]$month
[1] 5 6 7 7
Note that some months are repetitive because more than one measurement was taken.
Is there any easy way to do it other than writing a lot like:
S[[1]]<-S[c(1:2),]; S[[2]]<-S[c(3:28),];
and so on ...?? because that's quite inefficient!