Join us for
RADAR: AI Edition

longitudinalData (version 2.1.2)

reshapeWide: ~ Function: reshapeWide ~

Description

This function reshapes a data frame in 'long' format (repeated measurements in the same column) into a data frame in 'wide' format (repeated measurements in separate columns).

Usage

reshapeWide(data, varFixed, varLong, varTime, varDrop)

Arguments

data
[data.frame]: a data frame in 'long' format (repeated measurements in the same column)
varFixed
[charater] or [vector(character)]: names of classical (non-longitudinal) variables, variables that does not vary with time (like sex, blood groups).
varLong
[charater] or [vector(character)]: names of longitudinal variables, variables that vary with time (like sex, blood groups).
varTime
[charater]: variable that record the time at witch the longitudinal variable have been measured (like ages, year, month).
varDrop
[charater] or [vector(character)]: variable that should not appears in the new data frame.

Value

  • A data frame in 'wide' format (repeated measurements in separate columns).

Details

This function reshapes a data frame in 'long' format (repeated measurements in the same column) into a data frame in 'wide' format (repeated measurements in separate columns). If one of the four arguments varFixed, varLong, varTime and varDrop is missing, it will take the value of all the variable non already include in one of the fields.

See Also

reshape.

Examples

Run this code
summary(Indometh)
reshapeWide(Indometh,varTime="time",varFixed="Subject",varLong="conc")


df2 <- data.frame(id = rep(1:4, rep(2,4)),
                 visit = I(rep(c("Before","After"), 4)),
                 x = rnorm(4), y = runif(4),
                 sex=rep(c("H","F","H"),time=c(4,2,2)))[1:7,]
reshapeWide(df2,varTime="visit",varFixed="id",varLong=c("x","y"))
reshapeWide(df2,varTime="visit",varFixed=c("id","sex"),varLong=c("x"))
reshapeWide(df2,varTime="visit",varFixed=c("id","sex"),varDrop="")

Run the code above in your browser using DataLab