I have, what I think is a very simple question but can't figure it out or find the exact problem online. I want to order my dataset by id and time 1:4 so that it is in the sequence 1,2,3,4 not 1,1,1,2,2,2,3,4. See example:
dff <- data.frame (id=c(1,1,1,1,1,1,1,1,2,2,2,3),
time=c(1,1,2,2,3,3,4,4,1,1,2,1))
R>dff
id time
1 1 1
2 1 1
3 1 2
4 1 2
5 1 3
6 1 3
7 1 4
8 1 4
9 2 1
10 2 1
11 2 2
12 3 1
I want the resulting dataset to be ordered as follows:
R>dff
id time
1 1 1
2 1 2
3 1 3
4 1 4
5 1 1
6 1 2
7 1 3
8 1 4
9 2 1
10 2 2
11 2 1
12 3 1
I would preferably like to use arrange
function in dplyr
but will take any solution. I believe I should be creating a vector v<-c(1,2,3,4) and ordering with this using %in% but I'm not sure how. Something like this would i think just order 1,1,1 which is not what I want.
Any help appreciated, thanks.