stack
Stack data from input table or timetable into one variable of output table or timetable
Description
stacks data from multiple variables of the input table or timetable into one
variable of the output table or timetable. The input argument
S
= stack(U
,vars
)vars
specifies the variables to stack. The function
interleaves values from variables of the input into the output. It also adds an
indicator variable to the output. In each row of the
output, the value of the indicator variable indicates which variable of the input
provided the data.
If the input has N
rows and vars
specifies
M
variables, then the output has M*N
rows.
In general, the output contains fewer variables, but more rows, than the
input.
The indicator variable of the output has the categorical
data
type. You can use the indicator variable as a grouping variable when you call
functions such as groupsummary
or varfun
on the stacked data.
If vars
does not specify all variables in the input table or
timetable, then the values of the remaining variables are not stacked with values
from the variables specified by vars
. Instead,
stack
replicates the unstacked variables into their own
variables in the output.
If the input is a table with row names, then you cannot stack its row names in the output.
If the input is a timetable, then you cannot stack its row times in the output.
specifies options using one or more name-value arguments in addition to the input
arguments in previous syntaxes. For example, you can specify your own names for the
new and stacked variables in the output.S
= stack(___,Name=Value
)
Examples
Input Arguments
Name-Value Arguments
Output Arguments
Extended Capabilities
Version History
Introduced in R2013b