Learn R Programming

splitstackshape (version 1.2.0)

merged.stack: Take a list of stacked data.tables and merge them

Description

A wrapper around the Stacked function to merge the resulting list into a single data.table.

Usage

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

Arguments

data
The input data.frame.
id.vars
The columns to be used as "ID" variables.
var.stubs
The prefixes of the variable groups.
sep
The character that separates the "variable name" from the "times" in the source data.frame.
keep.all
Logical. Should all the variables in the source data.frame be kept (keep.all = TRUE) or only those which comprise the id.vars and split data from the var.stubs (keep.all = FALSE).
...
Further arguments to NoSep in case the separator is of a different form.

Value

  • A merged data.table.

See Also

Stacked, Reshape

Examples

Run this code
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
merged.stack(mydf, id.vars = c("id_1", "id_2"),
             var.stubs = c("varA", "varB", "varC"),
             sep = "\\.")

rm(mydf)

Run the code above in your browser using DataLab