Sort
Sort using Data Table
Summary: Sorts the 'Shuffle' column in ascending order and outputs a sorted table, demonstrating data manipulation capabilities in JMP.
Code:
// Source
// Open data table
dt = Open("data_table.jmp");
// Source
Data Table("data_table") << Sort(
By( :Shuffle ),
Order( Ascending ),
Output Table(
"Sort of Join of Chocolate Factory with Untitled 3 by Shuffle"
)
);
Code Explanation:
- Open table.
- Sort data by "Shuffle".
- Sort order ascending.
- Output sorted table.
Example 1
Summary: Runs data sorting and conversion to matrix, while defining certificate vectors and matrices.
Code:
dt = Open( "$SAMPLE_DATA/data_table.jmp", "private" );
dt << Sort( By( :yield ), Order( Descending ), Replace Table );
m = dt << get as matrix;
Close( dt, No save );
cert v = [2, 2, 2, 3, 4, 4, 4, 5, 8, 9, 17, 32864, 1281, 9454, 18847, 19200];
cert m = [8.6 1, 9.2 1, 12.1 1, 18 1, 8.2 1, 10.4 1, 9.9 1, 10.6 1, 7.4 2, 16 2, 15.9 2, 10.1 2, 9.8 2, 8.2 2, 8.8 2, 8.8 2];
Code Explanation:
- Open data table;
- Sort by yield in descending order.
- Replace original table with sorted data.
- Convert sorted data to matrix.
- Close dataset without saving.
- Define certificate vector.
- Define certificate matrix.
Example 2
Summary: Filters and sorts a data table to extract female students aged 14 or younger, applying color scheme 8 and row state coloring.
Code:
dt = Open( "$SAMPLE_DATA/data_table.jmp", invisible );
dt << select where( :sex == "F" & :age <= 14 );
dt << colors( 8 );
dt << color rows by row state;
dt << Sort( By( :name ), Order( Ascending ), Output Table( "Sort of data_table by name" ) );
Code Explanation:
- Open data table.
- Select female students.
- Filter students aged 14 or younger.
- Apply color scheme 8.
- Color rows by selection state.
- Sort data by name.
- Output sorted table.
Example 3
Summary: Prepares data by sorting a table, converting it to a matrix, and defining vectors and matrices for further analysis.
Code:
dt = Open("data_table.jmp");
dt << Sort( By( :yield ), Order( Descending ), Replace Table );
m = dt << get as matrix;
Close( dt, No save );
cert v = [2, 2, 2, 3, 4, 4, 4, 5, 8, 9, 17, 32864, 1281, 9454, 18847, 19200];
cert m = [8.6 1, 9.2 1, 12.1 1, 18 1, 8.2 1, 10.4 1, 9.9 1, 10.6 1, 7.4 2, 16 2, 15.9 2, 10.1 2, 9.8 2, 8.2 2, 8.8 2, 8.8 2];
Code Explanation:
- Open data table.
- Sort data by yield descending.
- Replace original table with sorted data.
- Convert data table to matrix.
- Close data table without saving.
- Define vector cert v.
- Define matrix cert m.
Example 4
Summary: Sorts a data table based on transformed columns, utilizing formulas to adjust values and ordering in ascending order.
Code:
dt1 = Open("data_table.jmp");
dt2 = dt1 << Sort(
By(
Transform Column( "-Cause Code", Formula( -:Cause Code ) ),
Transform Column( "Abs[Time Cycles]", Formula( Abs( :Time Cycles ) ) )
),
Order( Ascending, Ascending )
);
Code Explanation:
- Open data table;
- Assign to variable
dt1. - Sort data table
dt1. - Use transformation column for sorting.
- Transform
-Cause Codeusing formula. - Transform
Abs[Time Cycles]using formula. - Sort by transformed columns.
- Order in ascending order.
- Result assigned to
dt2.
Sort using New Column
Example 1
Summary: Process of creating a new column 'RS Col' and sorting a data table by this column, utilizing JMP's scripting language.
Code:
dt = Open( "$SAMPLE_DATA/data_table.jmp", "private" );
dt << New Column( "RS Col", Row State, Row State, Set Values( [4, 2, 4, 2, 4, 2, 5, 3, 18847, 9454, 19200, 1281, 32864, 17, 8, 9] ) );
dt << Sort( By( :RS Col ), Replace Table );
m = dt << Get as Matrix;
Code Explanation:
- Open data table;
- Create new column "RS Col".
- Set values for "RS Col".
- Sort table by "RS Col".
- Replace original table with sorted table.
- Convert table to matrix.
Example 2
Summary: Creates and manipulates new columns in a JMP data table, including numeric and character columns with formulas, and retrieves values from these columns.
Code:
dt = Open( "$SAMPLE_DATA/data_table.jmp", "private" );
dt << New Column( "Column 6", Numeric, Continuous, Format( "Best", 8 ), Formula( :age + :height ) );
dt << New Column( "Column 7", Character, Nominal, Formula( :name || :sex ) );
dt << runFormulas;
dt << Sort( By( :Column 6 ), Replace Table );
vector1 = :column 6 << Get Values;
dt << Sort( By( :Column 7 ), Replace Table );
list1 = :column 7 << Get Values;
formula1 = Char( :Column 6 << Get Formula );
formula2 = Char( :Column 7 << Get Formula );
:height[1] = 100;
:name[1] = "ZELDA";
vector1 = :column 6 << Get Values;
list1 = :column 7 << Get Values;
Code Explanation:
- Open data table;
- Create new numeric column "Column 6".
- Define formula for "Column 6".
- Create new character column "Column 7".
- Define formula for "Column 7".
- Run all formulas in dataset.
- Sort table by "Column 6".
- Retrieve values from "Column 6".
- Sort table by "Column 7".
- Retrieve values from "Column 7".
Example 3
Summary: Creates a summary report with grouped data, calculating sums and means for 'height' and 'weight', and sorting by row count in descending order.
Code:
dt = Open("data_table.jmp");
dt << New Column( "age2",
Numeric,
Ordinal,
Format( "Fixed Dec", Use thousands separator, 5, 0 ),
List Check( {12, 13, 14, 15, 16, 17} ),
Set Values(
[12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
15, 16, 16, 16, 17, 17, 17]
)
);
dtsum = dt << Summary( Group( :age2 ), Sum( :height ), Mean( :weight ), output table name( "SummaryOutput" ) );
dtsort = dtsum << Sort( By( :N Rows ), Order( Descending ), Output Table( "crash" ) );
Close( dtsort, nosave );
Code Explanation:
- Open data table.
- Create new column "age2".
- Define column properties.
- Set column values.
- Generate summary report.
- Group by age2.
- Summarize height and weight.
- Name output table.
- Sort by row count descending.
- Close sorted table without saving.
Example 4
Summary: Creates a summary table with grouped data, summarized height and weight, and named 'SummaryOutput', using JMP's scripting language.
Code:
dt = Open("data_table.jmp");
dt << New Column( "age2",
Numeric,
Ordinal,
Format( "Fixed Dec", Use thousands separator, 5, 0 ),
List Check( {12, 13, 14, 15, 16, 17} ),
Set Values(
[12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15,
15, 16, 16, 16, 17, 17, 17]
)
);
dtsum = dt << Summary( Group( :age2 ), Sum( :height ), Mean( :weight ), output table name( "SummaryOutput" ) );
dtsort = dtsum << Sort( By( :N Rows ), Order( Descending ), Output Table( "crash" ) );
Code Explanation:
- Open data table.
- Create new column "age2".
- Define "age2" as numeric and ordinal.
- Set format for "age2".
- Define valid values for "age2".
- Assign values to "age2".
- Create summary table.
- Group by "age2".
- Summarize height and weight.
- Name summary table "SummaryOutput".
Example 5
Summary: Process of sorting a data table by a new column and retrieving its values, converting it to a matrix for further analysis.
Code:
dt = Open("data_table.jmp");
dt << New Column( "RS Col", Row State, Row State, Set Values( [4, 2, 4, 2, 4, 2, 5, 3, 18847, 9454, 19200, 1281, 32864, 17, 8, 9] ) );
dt << Sort( By( :RS Col ), Replace Table );
m = dt << Get as Matrix;
v = :RS Col << Get Values;
Code Explanation:
- Open data table.
- Add new column "RS Col".
- Set values for "RS Col".
- Sort data table by "RS Col".
- Replace original table with sorted table.
- Convert data table to matrix.
- Retrieve values from "RS Col".
Example 6
Summary: Creates and manipulates new columns in a JMP data table, including numeric and character columns with formulas, and retrieves sorted values from these columns.
Code:
dt = Open("data_table.jmp");
dt << New Column( "Column 6", Numeric, Continuous, Format( "Best", 8 ), Formula( :age + :height ) );
dt << New Column( "Column 7", Character, Nominal, Formula( :name || :sex ) );
dt << runFormulas;
dt << Sort( By( :Column 6 ), Replace Table );
vector1 = :column 6 << Get Values;
dt << Sort( By( :Column 7 ), Replace Table );
list1 = :column 7 << Get Values;
formula1 = Char( :Column 6 << Get Formula );
formula2 = Char( :Column 7 << Get Formula );
:height[1] = 100;
:name[1] = "ZELDA";
vector1 = :column 6 << Get Values;
list1 = :column 7 << Get Values;
Code Explanation:
- Open data table.
- Create new numeric column.
- Create new character column.
- Run column formulas.
- Sort table by numeric column.
- Retrieve sorted values from numeric column.
- Sort table by character column.
- Retrieve sorted values from character column.
- Get formula for numeric column.
- Get formula for character column.
- Modify height value.
- Modify name value.
- Retrieve updated values from numeric column.
- Retrieve updated values from character column.
Example 7
Summary: Runs the Wilcoxon Signed Rank Test with Pratt Option to analyze SO2 values, generating a table with scaled and transformed data.
Code:
dt = Open("data_table.jmp");
row = dt << getrowswhere( :SO2 >= 0 );
chem = :SO2[row];
dt1 = New Table( "Wilcoxon Signed Rank Test, Pratt Option", New Column( "SO2", Numeric, Continuous, Set Values( chem * 1000 ) ) );
dt1 << New Column( "diff", Numeric, Continuous, Formula( :SO2 - 0.052 * 1000 ) );
dt1 << New Column( "absDiff", Numeric, Continuous, Formula( Abs( :diff ) ) );
dt1 << sort( replace table, by( absDiff ), order( ascending ) );
dt1 << New Column( "sign", Numeric, Continous, Formula( If( :diff == 0, 0, :diff / :absdiff ) ) );
dt1 << New Column( "unsignedRank", Numeric, Continous );
map = Associative Array( dt1:absDiff );
uniqueAbsDiff = map << getkeys;
len = Length( uniqueAbsDiff );
For( j = 1, j <= len, j++,
value = uniqueAbsDiff[j];
row = dt1 << getrowswhere( :absDiff == value );
map[value] = N Row( row );
newrank = (Min( row ) + Max( row )) / 2;
:unsignedRank[row] = newrank;
);
dt1 << New Column( "signRank", Numeric, Countinous, Formula( :sign * :unsignedRank ) );
posIndex = dt1 << getrowswhere( :signRank > 0 );
Code Explanation:
- Open data table.
- Filter rows where SO2 >= 0.
- Extract SO2 values.
- Create new table for analysis.
- Add SO2 column with scaled values.
- Add diff column with formula.
- Add absDiff column with formula.
- Sort table by absDiff.
- Add sign column with formula.
- Add unsignedRank column.
Sort using Delete Rows
Summary: Process of filtering a data table, selecting rows where age is less than 14, and extracting the selected column as a matrix.
Code:
dt = Open("data_table.jmp");
dt << Delete Rows( 21 :: 40 );
dt << Select Where( :age < 14 );
dt << Name Selection in Column( Column Name( "Younger" ), Selected( 1 ), unselected( 0 ) );
m = dt:Younger << Get As Matrix();
Close( dt, nosave );
certscpt =
"New Table(\!"MySortedTable\!", Add Rows(3), New Script(\!"Source\!", Data Table(\!"MyTable\!") << Sort(By(:c1), Order(Descending), Output Table(\!"MySortedTable\!"))), New Column(\!"c1\!", Numeric, \!"Continuous\!", Format(\!"Best\!", 12), Set Property(\!"Notes\!", \!"numeric column\!"), Set Values([3, 2, 1])), New Column(\!"c2\!", Character, \!"Nominal\!", Set Property(\!"Notes\!", \!"character column\!"), Set Values({\!"c\!", \!"b\!", \!"a\!"})))";
dt = New Table( "MyTable",
Add Rows( 3 ),
New Column( "c1", Numeric, Continuous, Format( "Best", 12 ), Set Property( "Notes", "numeric column" ), Set Values( [1, 2, 3] ) ),
New Column( "c2", Character, Nominal, Set Property( "Notes", "character column" ), Set Values( {"a", "b", "c"} ) )
);
dt2 = dt << Sort( By( :c1 ), Order( Descending ), Output Table( "MySortedTable" ) );
myscript = dt2 << get script();
charscpt = Char( Name Expr( myscript ) );
Close( dt2, nosave );
Close( dt, nosave );
rick = [1 1 1 54, 1 1 2 37, 1 2 1 49, 1 2 2 31];
Code Explanation:
- Open data table.
- Delete rows 21-40.
- Select rows where age < 14.
- Name selected rows "Younger".
- Extract "Younger" column as matrix.
- Close original data table.
- Define script for new table creation.
- Create new data table "MyTable".
- Sort "MyTable" by column c1 descending.
- Save sort script and close tables.
Sort using Set Property
Example 1
Summary: Creates a new table with formatted date columns and stacks these columns to generate a matrix.
Code:
dt = Open("data_table.jmp");
:age << Set Property( "Value Ordering", {17, 16, 13, 12} );
dt << Sort( by( age ), Replace Table );
v = dt:age << Get Values;
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.
- Sort table by age.
- Get age values.
- Close original table.
- Define matrix cert m.
- Create new table mytab.
- Add rows to new table.
- Add columns to new table.
- Stack columns in new table.
Example 2
Summary: Runs the sorting and reordering of a data table by age, replacing the original table with the sorted values.
Code:
dt = Open("data_table.jmp");
:age << Set Property( "Value Ordering", {17, 16, 13, 12} );
dt << Sort( by( age ), Replace Table );
v = dt:age << Get Values;
Code Explanation:
- Open data table.
- Set age value ordering.
- Sort table by age.
- Replace original table.
- Retrieve age values.
Sort using Summary
Example 1
Summary: Process of summarizing data by species and sorting it by the sum of miles, generating a sorted output table.
Code:
dt = Open("data_table.jmp");
dtsum = dt << Summary( Group( :species ), Sum( :miles ), output table name( "AnimalsSummaryOutput" ) );
dtsort = dtsum << Sort( By( Column( "Sum(miles)" ) ), Order( Ascending ), Output Table( "AnimalsSortOutput" ) );
Close( dtsort, nosave );
Code Explanation:
- Open data table;
- Create summary table.
- Sum miles by species.
- Name summary table.
- Sort summary table.
- Sort by sum of miles.
- Order in ascending.
- Output sorted table.
- Close sorted table.
- Do not save.
Example 2
Summary: Creates a summary table by species, summing miles and sorting the output in ascending order.
Code:
dt = Open("data_table.jmp");
dtsum = dt << Summary( Group( :species ), Sum( :miles ), output table name( "AnimalsSummaryOutput" ) );
dtsort = dtsum << Sort( By( Column( "Sum(miles)" ) ), Order( Ascending ), Output Table( "AnimalsSortOutput" ) );
Code Explanation:
- Open data table;
- Create summary table by species.
- Sum miles for each species.
- Name summary table "AnimalsSummaryOutput".
- Sort summary table by sum of miles.
- Sort order is ascending.
- Name sorted table "AnimalsSortOutput".
Sort using Rename Table Script
Summary: Runs data table operations, including renaming a script, running the renamed script, creating a new table with specific columns and values, and sorting the table by a column.
Code:
dt = Open("data_table.jmp");
dt << Rename Table Script( "Distribution", "Bivariate\X" );
dt << Run Script( "Bivariate\X" );
Close( dt, nosave );
dt = New Table( "mytab1",
Add Rows( 8 ),
New Column( "c1", Numeric, Continuous, Format( "Best", 12 ), Set Values( [5, 2, 1, 3, 4, 53, 4, 2] ) ),
New Column( "c2", Numeric, Nominal, Format( "Best", 12 ), Formula( Row() ) )
);
dt << Sort( by( c1 ), replace table );
Code Explanation:
- Open data table;
- Rename script "Distribution" to "BivariateX".
- Run renamed "BivariateX" script.
- Close dataset without saving.
- Create new table "mytab1".
- Add 8 rows to table.
- Add numeric column "c1" with continuous data.
- Set values for column "c1".
- Add nominal column "c2" with formula.
- Sort table by column "c1".
Sort using Control Chart
Example 1
Summary: Creates and configures control charts for Grade, utilizing data sorting, selection, and deletion, as well as customization of phase variables, group sizes, and KSigma settings.
Code:
dt = Open("data_table.jmp");
dtsorted = dt << sort( by( :Money ) );
dtsorted << select rows( {1, 2} );
dtsorted << delete rows;
obj = dtsorted << Control Chart(
Phase( :Money ),
Group Size( 1 ),
KSigma( 3 ),
Chart Col(
:Grade,
Individual Measurement(
Show Zones( 1 ),
Rule 10 X( 1 ),
Phase Level( "1" ),
Phase Level( "2" ),
Phase Level( "3" ),
Phase Level( "4" )
)
)
);
rpt = obj << report;
obj << Rule 10 X( 0 );
obj << Test 2( 1 );
rpt = obj << report;
obj = dtsorted << Control Chart(
Phase( :Money ),
Group Size( 1 ),
KSigma( 3 ),
Chart Col(
:Grade,
Individual Measurement( Test 8( 1 ), Phase Level( "1" ), Phase Level( "2" ), Phase Level( "3" ), Phase Level( "4" ) )
)
);
rpt = obj << report;
Code Explanation:
- Open table.
- Sort data by Money.
- Select first two rows.
- Delete selected rows.
- Create control chart for Grade.
- Set phase variable to Money.
- Set group size to 1.
- Set KSigma to 3.
- Enable Rule 10 X for phases 1-4.
- Disable Rule 10 X.
- Enable Test 2.
- Create new control chart with Test 8 for phases 1-4.
Example 2
Summary: Creates a control chart for NPN1 measurements across sites, with individual measurement tests applied and K Sigma set to 3.
Code:
dt = Open("data_table.jmp");
dtsorted = dt << sort( by( :SITE ) );
obj = dtsorted << Control Chart(
Phase( :SITE ),
Group Size( 1 ),
KSigma( 3 ),
Chart Col(
:NPN1,
Individual Measurement(
Test 7( 1 ),
Phase Level( "1" ),
Phase Level( "2" ),
Phase Level( "3" ),
Phase Level( "4" ),
Phase Level( "5" )
)
)
);
rpt = obj << report;
Code Explanation:
- Open data table.
- Sort data by site.
- Create control chart object.
- Set phase by site.
- Define group size as 1.
- Set K Sigma to 3.
- Add chart column for NPN1.
- Apply individual measurement test.
- Specify test 7 with level 1.
- Specify test 7 with levels 2-5.
Sort using Column
Summary: Runs recoding and sorting operations on a data table, utilizing the Recode platform to transform values and generate new columns.
Code:
dt1 = Open("data_table.jmp");
Column( dt1, "Sports" ) << set selected;
recodeobj = (dt1 << Recode( "Return" ))[1];
recodeobj << Change Value( "Soccer", "Snowboarding" );
recodeobj << GetNewDataCol();
recodeobj << Set sort by( "NewValues", 1 );
recodeobj << view groups( 1 );
recodeobj << Save Recode;
list1 = :Sports 2 << Get as matrix;
dt1 << Clear column selection;
Preferences( Recode Initial sort( 2 ) );
Column( dt1, "Family cars" ) << set selected;
recodeobj = (dt1 << Recode( "Return" ))[1];
recodeobj << Convert to Uppercase();
recodeobj << Set sort by( "OldValues", 0 );
list2 = recodeobj << GetNewDataCol();
recodeobj << Save Recode;
dt1 << Clear column selection;
Code Explanation:
- Open data table.
- Select "Sports" column.
- Initiate recode operation.
- Change "Soccer" to "Snowboarding".
- Retrieve new data column.
- Sort by new values.
- View groups.
- Save recode changes.
- Extract "Sports 2" as matrix.
- Clear column selection.
- Set recode initial sort preference.
- Select "Family cars" column.
- Initiate recode operation.
- Convert to uppercase.
- Sort by old values.
- Retrieve new data column.
- Save recode changes.
- Clear column selection.