Learn R Programming

longitudinalData (version 0.6.4)

as.longData: ~ Function: as.longData ~

Description

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

Usage

as.longData(data, id, timeCol, timeReal, varName,other)

Arguments

data
[data.frame] or [matrix]: structure containning the longitudinal data.
id
[character]: single identifier for each trajectory (ie each individual).
  • Ifdatais adata.frame, the defaultidis the first column of thedata.frame.
  • Ifdatais a
timeCol
[numeric]: column number in which longitudinal data can be found.
  • Ifdatais adata.frame, the defaulttimeColis all the column of thedata.framebut the first.
  • Ifdata
timeReal
[numeric]: time at which measures were made in "real" life. By default,timeReal is 0:(length(timeCol)-1).
varName
[character]: Name of the variable being measured ("V" by default).
other
[list]: list of additionnal information.

Value

  • An object of class LongData.

Details

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

See Also

longData, LongData

Examples

Run this code
#################
### Simple data.frame
df <- data.frame(id=11:12,Va1=c(1,4),Va2=c(2,5))
as.longData(df)


#################
### Complexe data.frame
df <- data.frame(id=11:12,Va1=c(1,4),To1=c(0.1,0.4),Va2=c(2,5),To2=c(0.1,0.3))

### Transformation in a LongData, selecting variable "Va"
as.longData(df,timeCol=c(2,4))

### Transformation in a LongData, selecting variable "To"
as.longData(df,timeCol=c(3,5))

### Changing the id's name
as.longData(df,id=c("Ind-1","Ind-2"),timeCol=c(2,4))

### Changing the real time and the variable name.
as.longData(df,timeCol=c(3,5,2,4),timeReal=c(1,2,4,8),varName="Size")



#################
### matrix
mat <- matrix(1:8,2,dimnames=list(c("I1","I2"),c("Size1.2","Size1.5","Size2.5","Size4")))
as.longData(mat)
as.longData(mat,timeReal=c(1.2,1.5,2.5,4))
as.longData(mat,timeReal=c(1.2,2.5,4),timeCol=c(1,3,4),varName="Size")

Run the code above in your browser using DataLab