Stack() combines values from several columns into one column.
dt << Stack(
Columns ( columns ), // the columns to stack together
Source Label Column ( "name" ), // to identify source columns
Stacked Data Column ( "name" ), // name for the new stacked column
Keep ( columns ), // the columns to keep in the data table
Drop ( columns ), // the columns to drop in the data table
Output Table ( "name" ), // name for the new data table
Columns( columns ) ); // specify which columns to include in the stacked table
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
StackedDt = dt << Stack(
Columns( :weight, :height ),
Source Label Column( "ID" ),
Stacked Data Column( "Y" ),
Name( "Non-stacked columns" )( Keep( :age, :sex ) ),
Output Table( "Stacked Table" )
);
The Columns(columns) argument can take a list of columns, or an expression that evaluates to a list.
dt = Open( "$SAMPLE_DATA/Blood Pressure.jmp" );
dt << Stack(
Columns(
:BP 8M,
:BP 12M,
:BP 6M,
:BP 8W,
:BP 12W,
:BP 6W,
:BP 8F,
:BP 12F,
:BP 6F
),
Stacked Data Column( "BP" ),
Source Label Column( "Day" ),
Number of Series( 3 ), // number of sets in each series
Contiguous,
// If you want to stack vertically. Otherwise, omit the argument.
);