For the latest version of JMP Help, visit JMP.com/help.


Publication date: 04/30/2021

Subset a Data Table

Subset() creates a new data table from rows that you specify. If you specify no rows, Subset uses the selected rows. If no rows are selected or specified, it uses all rows. If no columns are selected or specified, it uses all columns. And if Subset has no arguments, the Subset window appears.

dt << Subset((<"Private">|<"Invisible">), <Selected Columns>, <Columns(column list)>, <Selected Rows>, <Rows([number, number, ...])>, <By(column list)>, <Sampling Rate(fraction)>, <Sample Size(integer)>, <Stratify(column list)>, <Link to Original Data Table(Boolean)>, <Copy Formula(Boolean)>, <Suppress Formula Evaluation(Boolean)>, <Keep by Column>);

Note: For more arguments, see the Scripting Index in the Help menu.

For example, using Big Class.jmp, to select the columns for all rows in which the age is 12:

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
For Each Row( Selected( Row State() ) = (:age == 12) );
subdt = dt << Subset( Output Table Name( "Subset" ) );

To select three columns and all rows, run this script:

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
subDt1 = dt << Subset(
	Columns( :name, :age, :height ),
	Output Table Name( "Big Class 2" )
);

To select specified rows of two columns and link the two data tables, run this script:

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
subDt2 = dt << Subset(
	Columns( :name, :weight ),
	Rows( [2, 4, 6, 8] ),
	Linked
);

To select the columns for all rows in which the age is 12, run this script:

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Select Where( :age == 12 );
dt << Subset( ( Selected Rows ), Output Table Name( "Subset" ) );

To verify that rows were selected and then conditionally proceed to subset the current data table or open another data table, run this script:

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Select Where( :age == 12 );
 

/* If the condition selected no rows, open Fitness.jmp.

Else, generate the desired subset table of Big Class.jmp.*/

If( N Rows( dt << Get Selected Rows ) == 0,
 
newdt = Open( "$SAMPLE_DATA/Fitness.jmp" ),
   newdt = dt << Subset( All Columns( 1 ), Selected Rows( 1 ) )
);
Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).