reshapeWide {base}R Documentation

Reshape data frame to wide format

Description

(EXPERIMENTAL). Convert data frame with repeated measurements in long format, 1 row per observation to wide format with repeated observations in multiple variables across rows.

Usage

reshapeWide(x, i=reshape.i, j=reshape.j,
            val=reshape.v, jnames=levels(j))

Arguments

x The data frame to convert
i Factor or numeric. Indicates observations in same row of the wide format
j Factor or numeric. Indicates observations in same column of wide format
val Value to reshape for.
jnames Names of new variables in reshaped frame

Details

val, i, and j are interpreted relative to x. This essentially places the values of val in a table defined by i and j, which are assumed to span the data set (exactly one observation in each cell of their cross-tabulation). Any other variables in the data frame will be assumed to have the same value for all values of j (given i) and are collapsed into a single value.

Value

The reshaped data frame.

WARNING

There is no check that the names given to the new columns are valid identifiers or unique within the data frame. Variables in x are not checked to have constant values given i.

Bugs

There ought to be a way to have multiple val variables.

Note

The defaults are set to use the names that result from a call to reshapeLong.

See Also

reshapeLong, unstack

Examples

dd<-as.data.frame(matrix(1:24,4))
(dd1<-reshapeLong(dd,V3:V5))
reshapeWide(dd1)
reshapeWide(dd1,jnames=c("A","B","C"))