markVisits {epicalc}R Documentation

Mark visits of subjects in a long format

Description

Mark visits of subjects in a longitudinal data frame

Usage

markVisits(id, time)

Arguments

id

subject identification field

time

time of visit

Details

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.

Note

This was created from combination of the functions 'rle' and 'sapply'

Author(s)

Virasakdi Chongsuvivatwong <cvirasak@medicine.psu.ac.th>

See Also

'rle', 'sapply', 'sortBy'

Examples

## 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

[Package epicalc version 3.5.1.8 Index]