Learn R Programming

splitstackshape (version 1.0)

Stacked: stack columns from a wide form to a long form

Usage

Stacked(data, id.vars, var.stubs, sep, keep.all = TRUE,
    ...)

Arguments

data
The source data.frame.
id.vars
The variables that serve as unique identifiers.
var.stubs
The prefixes of the variable groups.
sep
The character that separates the "variable name" from the "times" in the wide data.frame.
keep.all
Logical. Should all the variables from the source data.frame be kept (keep.all = TRUE) or should the resulting data.table comprise only columns for
...
Further arguments to NoSep in case the separator is of a different form.

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. A function to conveniently stack groups of wide columns into a long form which can then be merged together. This is the function internally called by merged.stack. 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, id.vars = c("id_1", "id_2"), var.stubs = c("varA", "varB", "varC"), sep = "\\.")

    rm(mydf)

    [object Object],[object Object] stack, melt from "reshape2".