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

reshapeWide

~ Function: longToWide (or 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). It also correct a bug of reshape.

Usage

longToWide(trajLong)
reshapeLongToWide(trajLong)

Arguments

trajLong

[data.frame]: data.frame that hold the trajectories in long format. The data.frame has to be (no choice!) in the following format: the first column should be the individual indentifiant. The second should be the times at which the measurement are made and should be numeric. The third one should be the measurement.

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).

Value

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

Note

longToWide is just a 'friendly overlay' of the function reshape. It also corrects a reshape bug (modification of the order of some trajectories value when some times are missing).

Author(s)

Christophe Genolini

See Also

Examples

summary(Indometh)
longToWide(Indometh)


df2 <- data.frame(id = rep(LETTERS[1:4], rep(2,4)),
                 visit = I(rep(c("3","6"), 4)),
                 x = rnorm(4), y = runif(4),
                 sex=rep(c("H","F","H"),time=c(4,2,2)))[1:7,]
longToWide(df2[,1:3])
longToWide(df2[,c(1,2,4)])

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.