Main Content

Unstack data from single variable into multiple variables

converts the table or timetable, `U`

= unstack(`S`

,`vars`

,`ivar`

)`S`

, to an equivalent table or
timetable, `U`

, that is unstacked. `vars`

specifies variables in `S`

, each of which is unstacked into
multiple variables in `U`

. In general, `U`

contains more variables, but fewer rows, than `S`

.

The `ivar`

input argument specifies the variable in
`S`

that `unstack`

uses as an indicator
variable. The values in `ivar`

determine which variables in
`U`

contain elements taken from `vars`

after
unstacking.

The `unstack`

function treats the remaining variables
differently in tables and timetables.

If

`S`

is a table, then`unstack`

treats the remaining variables as grouping variables. Each unique combination of values in the grouping variables identifies a group of rows in`S`

that is unstacked into a single row of`U`

.If

`S`

is a timetable, then`unstack`

discards the remaining variables. However,`unstack`

treats the vector of row times as a grouping variable.

You cannot unstack the row names of a table, or the row times of a timetable, or specify
either as the indicator variable. You can specify row names or row times as constant
variables with the `'ConstantVariables'`

argument.

converts
the table or timetable `U`

= unstack(`S`

,`vars`

,`ivar`

,`Name,Value`

)`S`

with additional options
specified by one or more `Name,Value`

pair arguments.

For example, you can specify how `unstack`

converts variables from
`S`

to variables in `U`

.

You can specify more than one data variable in

`S`

, and each variable becomes a set of unstacked data variables in`U`

. Use a vector of positive integers, a cell array or string array containing multiple variable names, or a logical vector to specify`vars`

. The one indicator variable, specified by the input argument,`ivar`

, applies to all data variables specifies by`vars`

.

`stack`

| `join`

| Stack Table
Variables | Unstack Table
Variables | Join Tables