I am working on a data frame similar to this one here:
ID = c("1","1","1","1","1","1","1","2","2","2","2","2","2","2","2","2","2","2","2","2","2")
TIME = c("0", "0.5", "1","1.5","2","2.5","3","0","0", "0.5","0.5", "1","1","1.5","1.5","2","2","2.5","2.5","3","3")
OBS = c("0", "0.73", "0.98", "1.24", "2.06","2.56","4.01", "0", "0.03", "0.76", "0.85", "2.13","2.78","3.9", "4.1", "5.4", "5.6", "7.8", "8.0","8.4","8.8")
VISITNUM = c("1","1","1","1","1","1","1","1","2", "1","2","1","2","1","2","1","2","1","2","1","2")
DF = data.frame(ID, TIME, OBS, VISITNUM)
I am having trouble ordering the data frame - basically I want to order my data by the following time sequence:
TIMEORDERED <- c("0","0.5","1","1.5","2","2","2.5","3")
giving this
ID = c("1","1","1","1","1","1","1","2","2","2","2","2","2","2","2","2","2","2","2","2","2")
TIME = c("0", "0.5", "1","1.5","2","2.5","3","0", "0.5", "1","1.5","2","2.5","3","0", "0.5", "1","1.5","2","2.5","3")
OBS= c("0", "0.73", "0.98", "1.24", "2.06","2.56","4.01", "0", "0.76", "2.13","3.9", "5.4", "7.8", "8.4", "0.03", "0.85", "2.78", "4.1","5.6","8.0","8.8")
VISITNUM = c("1","1","1","1","1","1","1","1","1","1","1","1","1","1","2","2","2","2","2","2","2")
DFIWANT = data.frame(ID, TIME, OBS, VISITNUM)
The issue is there are measurements on the same subject (DF$ID = 2) (yet different visits, see DF$VISITNUM).
I suspect the order() function or the arrange() function in the plyr package are my friends, yet my attempts have not been fruitful.
Any help would be appreciated.
Sincerily
Y