What you need to do is just separate the dose records, merge with the original dataset before sorting it:
- # To read xls file
- library(gdata)
- orig <- read.xls("data.xls", perl = "perl.exe")
- # Separate dose records
- dose <- orig[orig$EVID == 1, ]
- # To sort data.frame
- library(reshape)
- # Merge & sort
- target <- sort_df(rbind(orig, dose), c("ID", "TIME"))
- # Output dataset as csv file
- # You can save it as xls in Excel, if you wish
- write.csv(target, file = "target.csv", quote = FALSE, na = "", row.names = FALSE)
复制代码A few comments:
1. There may be other ways to do this task. I prefer this one because I can modify the separated dose records (change CMT, RATE, etc) for different absorption models.
2. I do not know what is your data source. In my experience, the dose and concentration data almost always come from different sources. If I need to do the data management myself, I will keep those 2 sources of data separated right before I finish. That gives you more flexibility.
3. ASCII files are preferred than xls as it is easy to be imported into R and can be used by NM.
Glad to see another NMuser.