Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

reshapeLong

~ Function: wideToLong (or reshapeWideToLong) ~


Description

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

Usage

wideToLong(trajWide,times=1:(ncol(trajWide)-1))
reshapeWideToLong(trajWide,times=1:(ncol(trajWide)-1))

Arguments

trajWide

[data.frame]: a data frame in 'wide' format (repeated measurements in separate column). The first column has to be the individual indentier. All the other column should be the trajectories.

times

[vector(numeric)]: specification of the times at wich the longitudinal data have been measured (like ages, year, month). If times is missing, it takes the value 1:(ncol(trajWide)-1).

Details

This function reshapes a data frame in 'wide' format (repeated measurements in separe column) into a data frame in 'long' format (repeated measurements in the same columns). The first column has to be the individual indentier. All the other column should be the trajectories. The missing values are removed in long format.

Value

A data frame in 'long' format.

Author(s)

Christophe Genolini

See Also

Examples

df3 <- data.frame(id = LETTERS[rep(1:4)], sex=c("H","F","H","F"),
    v1=rnorm(4),v2=rnorm(4),w1=rnorm(4),w2=rnorm(4))

wideToLong(df3[,c(1,3,4)])
wideToLong(df3[,c(1,5,6)])
wideToLong(df3[,c(1,3:6)])
wideToLong(df3[,c(1,3:6)],times=c(1,2,4,8))

longitudinalData

Longitudinal Data

v2.4.1
GPL (>= 2)
Authors
Christophe Genolini [cre, aut], Bruno Falissard [ctb], Dai Fang [ctb], Luke Tierney [ctb]
Initial release
2016-02-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.