| Stacked {splitstackshape} | R Documentation |
Stack Columns from a Wide Form to a Long Form
Description
A function to conveniently stack groups of wide columns into a long form
which can then be merged together.
Usage
Stacked(data, id.vars = NULL, var.stubs, sep, keep.all = TRUE,
keyed = TRUE, keep.rownames = FALSE, ...)
Arguments
data |
The source |
id.vars |
The variables that serve as unique identifiers. Defaults to |
var.stubs |
The prefixes of the variable groups. |
sep |
The character that separates the "variable name" from the "times"
in the wide |
keep.all |
Logical. Should all the variables from the source
|
keyed |
Logical. Should the |
keep.rownames |
Logical. Should rownames be kept when converting the input to a |
... |
Other arguments to be passed on when |
Value
A list of data.tables with one data.table for
each "var.stub". The key is set to the
id.vars and .time_# vars.
Note
This is the function internally called by merged.stack.
Author(s)
Ananda Mahto
See Also
Examples
set.seed(1)
mydf <- data.frame(id_1 = 1:6, id_2 = c("A", "B"),
varA.1 = sample(letters, 6),
varA.2 = sample(letters, 6),
varA.3 = sample(letters, 6),
varB.2 = sample(10, 6),
varB.3 = sample(10, 6),
varC.3 = rnorm(6))
mydf
Stacked(data = mydf, var.stubs = c("varA", "varB", "varC"), sep = ".")