Stack: Stack columns from a data frame and include variables.

Description Usage Arguments Value See Also Examples

View source: R/Stack.R

Description

Stack columns from a data frame and include variables.

Usage

1
2
3
Stack(data, stackVar = 1:NCOL(data), blockVar = integer(0),
  rowData = data.frame(stackVar)[, integer(0), drop = FALSE],
  valueName = "values", indName = "ind")

Arguments

data

A data frame

stackVar

Indices of variables to be stacked

blockVar

Indices of variables to be replicated

rowData

A separate data frame where NROW(rowData)=length(stackVar) such that each row may contain multiple information of each stackVar variable. The output data frame will contain an extended variant of rowData.

valueName

Name of the stacked/concatenated output variable

indName

Name of the output variable with information of which vector in x the observation originated. When indName is NULL this variable is not included in output.

Value

A data frame where the variable ordering corresponds to: blockVar, rowData, valueName, indName

See Also

Unstack

Examples

1
2
3
4
5
6
7
8
9
 z <- data.frame(n=c(10,20,30), ssb=c('S','S','B'),
 Ayes=1:3,Ano=4:6,Byes=7:9,Bno=10:12)
 zRow <- data.frame(letter=c('A','A','B','B'),answer=c('yes','no','yes','no') )
 
 x <- Stack(z,3:6,1:2,zRow)
 
 Unstack(x,6,3:4,numeric(0),1:2)
 Unstack(x,6,5,numeric(0),1:2)
 Unstack(x,6,3:4,5,1:2)

SSBtools documentation built on May 29, 2017, 3:32 p.m.