Stack
Example 1
Summary: Opens a data table and stacks selected columns, specifying source label and stacked data columns, with the option to output the result in a new table.
Code:
// Stack MICs
// Open data table
dt = Open("data_table.jmp");
// Stack MICs
dt << Stack(
Columns( :penicillin, :streptomycin, :neomycin ),
Source Label Column( :Stack Source Label ),
Stacked Data Column( :Stack Data Column ),
Output Table( :Stack Output Table )
);
Code Explanation:
- Open data table.
- Stack selected columns.
- Specify source label column.
- Specify stacked data column.
- Specify output table.
Example 2
Summary: Runs the stacking and processing of specified columns in a JMP data table, with conditional checks for script suppression and formula evaluation.
Code:
dt = Open("data_table.jmp");
stackDt = dt << Stack(
columns( :hist0, :hist1, :hist3, :hist5 ),
Source Label Column( "Label" ),
Stacked Data Column( "Hist" ),
Output Table( "Stacked Table" )
);
form1 = Contains( Char( Column( stackDt, "diff" ) << get script ), "Suppress" );
form2 = Contains( Char( Column( stackDt, "mean" ) << get script ), "Suppress" );
Close( stackDt, no save );
stackDt = dt << Stack(
columns( :hist0, :hist1, :hist3, :hist5 ),
Source Label Column( "Label" ),
Stacked Data Column( "Hist" ),
Copy formula( 0 ),
Output Table( "Stacked Table" )
);
form1 = Contains( Char( Column( stackDt, "diff" ) << get script ), "Formula" );
form2 = Contains( Char( Column( stackDt, "mean" ) << get script ), "Formula" );
Close( stackDt, no save );
stackDt = dt << Stack(
columns( :hist0, :hist1, :hist3, :hist5 ),
Source Label Column( "Label" ),
Stacked Data Column( "Hist" ),
Copy formula( 1 ),
Suppress Formula Evaluation( 0 ),
Output Table( "Stacked Table" )
);
form1 = Contains( Char( Column( stackDt, "diff" ) << get script ), "Suppress" );
form2 = Contains( Char( Column( stackDt, "mean" ) << get script ), "Suppress" );
Code Explanation:
- Open data table.
- Stack specified columns into new table.
- Check if "diff" column has "Suppress" script.
- Check if "mean" column has "Suppress" script.
- Close stacked table without saving.
- Repeat stacking with "Copy formula" set to 0.
- Check if "diff" column has "Formula" script.
- Check if "mean" column has "Formula" script.
- Close stacked table without saving.
- Repeat stacking with "Copy formula" set to 1 and "Suppress Formula Evaluation" set to 0.
Example 3
Summary: Stacks specified columns in a JMP data table, labeling the source column and outputting a new table with stacked data.
Code:
dt = Open("data_table.jmp");
stackDt = dt << Stack(
columns( :hist0, :hist1, :hist3, :hist5 ),
Source Label Column( "Label" ),
Stacked Data Column( "Hist" ),
Copy formula( 0 ),
Output Table( "Stacked Table" )
);
sourceScript = Char( stackDt << Get Property( "Source" ) );
Code Explanation:
- Open data_table data
- Stack specified columns.
- Label source column as "Label".
- Name stacked data column as "Hist".
- Do not copy formulas.
- Output new table named "Stacked Table".
- Retrieve source script property.
- Convert source script to character string.
Example 4
Summary: Stacks selected columns, creation of source label and stacked data columns, and output table naming, while also checking for 'Suppress' in column scripts.
Code:
dt = Open("data_table.jmp");
stackDt = dt << Stack(
columns( :hist0, :hist1, :hist3, :hist5 ),
Source Label Column( "Label" ),
Stacked Data Column( "Hist" ),
Output Table( "Stacked Table" )
);
form1 = Contains( Char( Column( stackDt, "diff" ) << get script ), "Suppress" );
form2 = Contains( Char( Column( stackDt, "mean" ) << get script ), "Suppress" );
Code Explanation:
- Open data table.
- Stack selected columns.
- Create source label column.
- Create stacked data column.
- Name output table.
- Check for "Suppress" in "diff" column script.
- Check for "Suppress" in "mean" column script.
Example 5
Summary: Stacks and filters data from a primary source table, generating a new stacked table with specific columns and properties.
Code:
dt = Open("data_table.jmp");
dt2 = dt << Stack(
columns( :BP 8M, :BP 12M, :BP 6M, :BP 8W, :BP 12W, :BP 6W, :BP 8F, :BP 12F, :BP 6F ),
Source Label Column( "Day" ),
Stacked Data Column( "BP" ),
Stack by Row( 37 ),
Number of Series( 3 ),
Contiguous
);
dt2:Day << Set Property( "List Check", {"BP 12M", "BP 6M", "BP 8M"} );
lc = Char( dt2:Day << Get Property( "List Check" ) );
For Each Row(
alert = 0;
i = Row();
If( Contains( dt2:Day[i], "F" ),
alert = 1
);
If( Contains( dt2:Day[i], "W" ),
alert = 1
);
);
Close( dt2, nosave );
Close( dt, nosave );
dt = New Table( "Drug Trials",
Add Rows( 7 ),
New Column( "High Dose", Numeric, Continuous, Format( "Best", 10 ), Set Values( [6, 8, 11, 4, 13, 8, 0] ) ),
New Column( "Low Dose", Numeric, Continuous, Format( "Best", 10 ), Set Values( [2, 3, 18, 14, 9, 1, 9] ) ),
New Column( "Placebo", Numeric, Continuous, Format( "Best", 10 ), Set Values( [13, 18, 23, 12, 16, 12, 20] ) )
);
dt2 = dt << Stack( columns( :High Dose, :Low Dose, :Placebo ), Stack By Row( 0 ), );
Code Explanation:
- Open data table;
- Stack selected columns into new table.
- Set property for "Day" column.
- Convert property to character.
- Loop through each row.
- Check for "F" or "W" in "Day".
- Close stacked table without saving.
- Close original table without saving.
- Create new table "Drug Trials".
- Stack columns from new table.
Example 6
Summary: Stacks and filters a data table to identify rows containing specific labels, utilizing JMP's Stack platform.
Code:
dt = Open("data_table.jmp");
dt2 = dt << Stack(
columns( :BP 8M, :BP 12M, :BP 6M, :BP 8W, :BP 12W, :BP 6W, :BP 8F, :BP 12F, :BP 6F ),
Source Label Column( "Day" ),
Stacked Data Column( "BP" ),
Stack by Row( 37 ),
Number of Series( 3 ),
Contiguous
);
dt2:Day << Set Property( "List Check", {"BP 12M", "BP 6M", "BP 8M"} );
lc = Char( dt2:Day << Get Property( "List Check" ) );
For Each Row(
alert = 0;
i = Row();
If( Contains( dt2:Day[i], "F" ),
alert = 1
);
If( Contains( dt2:Day[i], "W" ),
alert = 1
);
);
Code Explanation:
- Open data table;
- Stack selected columns into new table.
- Label stacked columns as "Day" and "BP".
- Set stack properties by row and series.
- Enable list check for specific labels.
- Retrieve checked labels from "Day" column.
- Initialize alert variable.
- Loop through each row in the table.
- Check if "Day" contains "F" or "W".
- Set alert to 1 if condition met.
Stack using Delete Column
Summary: Prepares data by opening a data table, deleting the 'age' column, stacking all columns, and creating a subset of the first 20 rows.
Code:
dt = Open("data_table.jmp");
dt << Delete Column( age );
dts = dt << Stack( columns( all columns ), output table name( "Stacked" ) );
dtsub = dts << Subset( Rows( [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] ), output table name( "Test" ) );
Code Explanation:
- Open data table;
- Delete "age" column.
- Stack all columns.
- Name stacked table "Stacked".
- Subset first 20 rows.
- Name subset table "Test".
Stack using Set Property
Summary: Runs data analysis by creating summary tables and extracting column names, utilizing JMP scripting language (JSL) to manipulate data tables.
Code:
dt = Open("data_table.jmp");
dt:age << Set Property( "Value Ordering", {17, 16, 15, 12, 13, 14} );
dt2 = dt << Summary( Group( :age ), Mean( :height ) );
v = dt2:age << get values;
Close( dt2, nosave );
cert n = {"sex", "N Rows", "Mean(height, 17)", "Mean(height, 16)", "Mean(height, 15)", "Mean(height, 12)", "Mean(height, 13)",
"Mean(height, 14)"};
dt2 = dt << Summary( Group( :sex ), Mean( :height ), Subgroup( :age ) );
n = dt2 << get column names( string );
Close( dt2, nosave );
Close( dt, nosave );
cert m = [3358713600 3358800000, 3358886400 3358972800, 3359059200 .];
dt = New Table( "mytab",
Add Rows( 1 ),
New Column( "c2", Numeric, Continuous, Format( "m/d/y", 12 ), Input Format( "m/d/y" ), Set Values( [3358713600] ) ),
New Column( "c3", Numeric, Continuous, Format( "m/d/y", 12 ), Set Values( [3358800000] ) ),
New Column( "c4", Numeric, Continuous, Format( "m/d/y", 12 ), Set Values( [3358886400] ) ),
New Column( "c5", Numeric, Continuous, Format( "m/d/y", 12 ), Set Values( [3358972800] ) ),
New Column( "c6", Numeric, Continuous, Format( "m/d/y", 12 ), Set Values( [3359059200] ) )
);
dts = dt << Stack(
columns( :c2, :c3, :c4, :c5, :c6 ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ),
Number of Series( 2 )
);
m = dts << Get As Matrix;
Close( dts, nosave );
Close( dt, nosave );
cert n = {name, age, sex, height, weight};
Code Explanation:
- Open data table.
- Set age value ordering.
- Create summary table by age.
- Extract ages from summary table.
- Close summary table.
- Define certificate names.
- Create summary table by sex and age.
- Extract column names from summary table.
- Close summary table.
- Define certificate matrix.
Stack using Group Columns
Example 1
Summary: Runs data manipulation and analysis by opening a data table, grouping columns, stacking selected columns, retrieving column names, and creating a new table with formulas.
Code:
dt = Open("data_table.jmp");
dt << Group Columns( "Group1", BP 8M, 9 );
stackDt = dt << Stack(
columns( :BP 8M, :BP 12M, :BP 6M, :BP 8W, :BP 12W, :BP 6W, :BP 8F, :BP 12F, :BP 6F ),
Source Label Column( "Day" ),
Stacked Data Column( "BP" ),
Output Table( "Stacked" )
);
colNames = stackDt << Get Column Names();
Close( stackDt, no save );
Close( dt, no save );
dt = New Table( "Example",
Add Rows( 100000 ),
New Column( "Col",
Numeric,
Continuous,
Format( "Best", 10 ),
Formula(
If( Row() == 1,
r = 1,
r = r + 1
);
If( r != Row(),
Show( "failed", r, Row() )
);
r;
)
)
);
dt << RunFormulas;
dt << New Column( "Compare", Numeric, Continuous, Format( "Best", 12 ), Formula( If( :Col == Row(), 0, 1 ) ) );
dt << RunFormulas;
act val = Col Sum( :compare );
Close( dt, no save );
dt1 = New Table( "Example", Add Rows( 4000 ) );
For( c = 1, c <= 50, c++,
dt1 << New Column( "Col",
Numeric,
Continuous,
Formula(
If( Row() == 1,
Random Reset( 12345 );
Random Uniform();
,
Random Uniform()
)
)
)
);
dt1 << delete Columns( 1 );
m = dt1 << Get As Matrix();
act val = Loc( V Std( m` ) != 0 );
Code Explanation:
- Open data table;
- Group columns by Group1.
- Stack selected columns into new table.
- Retrieve column names from stacked table.
- Close stacked table without saving.
- Close original table without saving.
- Create new table named Example.
- Add 100,000 rows to Example.
- Add numeric column Col with formula.
- Run formulas in Example table.
Example 2
Summary: Prepares data by grouping columns, stacking selected variables, and retrieving column names from a JMP data table.
Code:
dt = Open("data_table.jmp");
dt << Group Columns( "Group1", BP 8M, 9 );
stackDt = dt << Stack(
columns( :BP 8M, :BP 12M, :BP 6M, :BP 8W, :BP 12W, :BP 6W, :BP 8F, :BP 12F, :BP 6F ),
Source Label Column( "Day" ),
Stacked Data Column( "BP" ),
Output Table( "Stacked" )
);
colNames = stackDt << Get Column Names();
Code Explanation:
- Open data table;
- Group columns by Group1.
- Stack selected columns.
- Label source as Day.
- Name stacked data as BP.
- Output stacked table as "Stacked".
- Retrieve column names from stacked table.
Stack using Set Name
Summary: Prepares data by opening a data table, selecting specific columns, stacking them, and converting the result to a matrix.
Code:
dt = Open("data_table.jmp");
dt << Set Name( "data_table" );
dt:age << Set Selected( 1 );
dt:height << Set Selected( 1 );
dt:weight << Set Selected( 1 );
dts = dt << Stack( columns( all selected columns ), output table name( "Stacked" ) );
stackMatrix = dts << get as matrix;
Code Explanation:
- Open data table.
- Rename table "data_table".
- Select age column.
- Select height column.
- Select weight column.
- Stack selected columns.
- Rename stacked table "Stacked".
- Convert stacked table to matrix.
Stack using Log Capture
Summary: Runs the opening and processing of a data table, defining variables, stacking columns, labeling source columns, and specifying output table names.
Code:
dt = Open("data_table.jmp");
li = {weight, height};
lcap = Log Capture(
Data Table("data_table") << Stack(
columns( li ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ),
Output Table( "foo" )
)
);
Code Explanation:
- Open data table.
- Define list of variables.
- Start log capture.
- Stack specified columns.
- Label source column.
- Name stacked data column.
- Specify output table name.
- Execute stack operation.
- End log capture.
- Store result in variable.
Stack using Data Table
Summary: Concatenates brand, softness, previous use, and temperature variables into three new columns with different formatting options.
Code:
Open("data_table.jmp");
Data Table("data_table") << Stack(
columns(
Transform Column(
"Concatenate[brand,softness,previous use,temperature]",
Character,
Formula( :brand || :softness || :previous use || :temperature )
),
Transform Column(
"Concatenate[brand,softness,previous use,temperature] 2",
Character,
Formula( :brand || " " || :softness || " " || :previous use || " " || :temperature )
),
Transform Column(
"Concatenate[brand,softness,previous use,temperature] 2 3",
Character,
Formula( :brand || ", " || :softness || ", " || :previous use || ", " || :temperature )
)
),
Source Label Column( "Label" ),
Stacked Data Column( "Data" )
);
Code Explanation:
- Open data table;
- Select data table.
- Begin stacking process.
- Transform first column.
- Define character type.
- Use concatenation formula.
- Transform second column.
- Define character type.
- Use concatenation formula with spaces.
- Transform third column.
- Define character type.
- Use concatenation formula with commas.
- Specify source label column.
- Specify stacked data column.