reshapeWide {base} | R Documentation |
(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.
reshapeWide(x, i=reshape.i, j=reshape.j, val=reshape.v, jnames=levels(j))
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 |
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.
The reshaped data frame.
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
.
There ought to be a way to have multiple val
variables.
The defaults are set to use the names that result
from a call to reshapeLong
.
dd<-as.data.frame(matrix(1:24,4)) (dd1<-reshapeLong(dd,V3:V5)) reshapeWide(dd1) reshapeWide(dd1,jnames=c("A","B","C"))