Stack | R Documentation |
Stack columns from a data frame and include variables.
Stack(
data,
stackVar = 1:NCOL(data),
blockVar = integer(0),
rowData = data.frame(stackVar)[, integer(0), drop = FALSE],
valueName = "values",
indName = "ind"
)
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. |
A data frame where the variable ordering corresponds to: blockVar, rowData, valueName, indName
Øyvind Langsrud
Unstack
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.