markVisits {epicalc} | R Documentation |
Mark visits of subjects in a longitudinal data frame
markVisits(id, time)
id |
subject identification field |
time |
time of visit |
Visit numbers are essential in longitudinal data analysis. This function makes it easy for R user to do so.
The data frame must be sorted first by 'id' and 'time'
If visits marked by this function is going to be further used for calculation of lag difference, there must not be any missing visit in the data set.
This was created from combination of the functions 'rle' and 'sapply'
Virasakdi Chongsuvivatwong <cvirasak@medicine.psu.ac.th>
'rle', 'sapply', 'sortBy'
## Data frame data(Sitka, package="MASS") use(Sitka) ## Classical R methods list1 <- rle(tree) list1 visit1 <- unlist(sapply(X=list1$lengths, FUN=function(x) 1:x, simplify=FALSE)) visit1 ## Do it again by Epicalc sortBy(tree, Time) visit2 <- markVisits(id=tree, time=Time) visit2