Learn R Programming

kml3d (version 0.7)

as.longData: ~ Function: as.longData ~

Description

as.longData turns a data.frame or a array into an object of class LongData.

Usage

## S3 method for class 'data.frame':
as.longData(data,idAll,time,timeDataFrame,varNames,maxNA=length(time)-2)
## S3 method for class 'array':
as.longData(data,idAll,time,varNames,maxNA=length(time)-2)

Arguments

data
[data.frame] or [matrix]: structure containning the trajectories.
idAll
[vector(character)]: single identifier for each trajectory (ie each individual). For a data.frame, the default value is the first column. For an array, the default value is the vector 1:dim(data)[1]
varNames
[vector(numeric)]: names of the variable. For a data.frame, the default is the names of the list provide to timeDataFrame. For an array, the default value is c(V1,V2,V3,...].
time
[vector(numeric)]: column number in which longitudinal data can be found. For a data.frame, the default is the length of the first argument of timeDataFrame. For an array, the default value is
timeDataFrame
[list(character=numeric,...)]: (for data.frame only) For each variable, timeDataFrame provide the column numbers that contain the trajectories. See example for details.
maxNA
[numeric] or [vector(numeric)]: Define, for each variable, the maximum number of missing values that a trajectory shall contain. Individual whose trajectory contains more missing value than maxNA are e

Value

  • An object of class LongData.

Author(s)

Christophe Genolini INSERM U669 / PSIGIAM: Paris Sud Innovation Group in Adolescent Mental Health Modal'X / Universite Paris Ouest-Nanterre- La Defense Contact author : genolini@u-paris10.fr

Details

as.longData turns a data.frame or a matrix into an object of class LongData.

References

Article "KmL: K-means for Longitudinal Data", in Computational Statistics, Volume 25, Issue 2 (2010), Page 317. Web site: http://christophe.genolini.free.fr/kml

See Also

longData, LongData

Examples

Run this code
#################
### data.frame
myDataFrame <- data.frame(id=11:12,Va11=c(1,4),Va15=c(2,5),Pe11=c(2,3),Pe15=c(3,2))
as.longData(myDataFrame,timeDataFrame=list(Va=c(2,3),Pe=c(4,5)))

### Some time can be missing (like V12 in the following):
myDataFrame2 <- data.frame(id=11:12,Va11=c(1,4),Pe11=c(2,5),Pe12=c(3,5),Va13=c(2,3),Pe13=c(1,3))
as.longData(myDataFrame2,time=c(11,12,13),timeDataFrame=list(Va=c(2,NA,5),Pe=c(3,4,6)))


#################
### array
f <- function(id,t)((id-1)%%3-1)*t
g <- function(id,t)(id%%2+1)*t
id2=1:120
time=c(1,2,3,4,8,12,16,20)

tra2 <- array(cbind(outer(id2,time,f),outer(id2,time,g))+rnorm(120*8*2,0,3),dim=c(120,8,2))
ld2 <- as.longData(tra2)

Run the code above in your browser using DataLab