
Last chance! 50% off unlimited learning
Sale ends in
stack(x, ...)
"stack"(x, ...)
"stack"(x, select, ...)
unstack(x, ...)
"unstack"(x, form, ...)
"unstack"(x, form, ...)
formula(x)
in the data frame method for unstack
.unstack
produces a list of columns according to the formula
form
. If all the columns have the same length, the resulting
list is coerced to a data frame.stack
produces a data frame with two columns:
x
.x
the
observation originated.stack
function is used to transform data available as
separate columns in a data frame or list into a single column that can
be used in an analysis of variance model or other linear model. The
unstack
function reverses this operation. Note that stack
applies to vectors (as determined by
is.vector
): non-vector columns (e.g., factors) will be
ignored (with a warning as from R 2.15.0). Where vectors of
different types are selected they are concatenated by
unlist
whose help page explains how the type of the
result is chosen.
These functions are generic: the supplied methods handle data frames
and objects coercible to lists by as.list
.
lm
, reshape
require(stats)
formula(PlantGrowth) # check the default formula
pg <- unstack(PlantGrowth) # unstack according to this formula
pg
stack(pg) # now put it back together
stack(pg, select = -ctrl) # omitting one vector
Run the code above in your browser using DataLab