I know how to make a subset table based on some criteria:
dt << Row Selection( Select where( (:Stat == "mean"), Current Selection( Extend )) ); dt << Select Columns( [10, 20] ); dt2 << Subset( Output Table( "test"), Selected Rows( 1 ), Selected columns( 1 ) );
But now I need to repeat the above for multiple criteria and stack the selection, i.e. the new table will have Column 10 as a fixed column, and then I keep adding column 20 with only the rows matching the criteria above. The number of rows will always be the same.
The "Stack" command does not work with selection, so am not sure what other commands can do that?
I suspect the issue is that the columns in both tables have the same names. Therefore, JMP will overwrite the values. Here is a simple example on how I would handle this. Now, given this type of Update, the two data tables will be lined up, row 1 with row 1.
That may result in the issue that you can not compare across columns, since the relationship between them does not exist.
dt << Row Selection( Select where( (:Freq == "F0"), Current Selection( Extend )) );
dt << Select Columns( [15,19] );
dt2 = dt << Subset( ( Selected Columns ), Output Table Name( "F0" ) );
dt << clear select;
dt << Row Selection( Select where( (:Freq == "F1"), Current Selection( Extend )) );
dt << Select Columns( [15,19] );
dt3 = dt << Subset( ( Selected Columns ), Output Table Name( "F1" ) );
// Rename the columns
column(dt3,1) <<set name((column(dt3,1) << get name) || " 2");
column(dt3,2) <<set name((column(dt3,2) << get name) || " 2");
// Merge the data tables
dt2 << update(with(dt3));
Here is an example of an easy way to delete the selected rows when using the Stack platform
names default to here(1);
// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Row Selection( Select where( (:Sex=="F"), Current Selection( "Extend" )) );
// Stack data table
dtStack = dt << Stack(
columns( :height, :weight ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" )
);
dtStack << delete rows;
Here is how I thought it can be done (but it is not working):
my_list = {"F0","F1"};
stackcols = {};
For( i = 1, i <= N Items( my_list ), i++,
dt << Row Selection( Select where( (:Freq==my_list[i]), Current Selection( "Extend" )) );
dt << Select Columns( [19] );
Insert Into( stackcols, dt )
);
dt2 << Subset( Output Table( "aa"), Selected Rows( 1 ), Selected columns( 1 ) );Basically, I filter the active table according to column "Freq", first by the value "F0" and then by "F1". This is located in Column 19. I add that selection to the selection list called 'stackcols'. So after the loop I am expecting this to be a two columns-wide list. Then I want to make a table out of it (Called "aa"). But it is not working.
Ah.....you are correct about deleting the selected rows. But to delete the non selected, just use
dtStack << Invert Row Selection;
and then delete the rows.
To append multiple independent Stacked data tables, simply:
dtBase = New Table("Base");
dtBase << Concatenate( dtStacked );
Close( dtStacked, nosave );
Thanks, but it didn't work:
dt = current data table();
my_list = {"F0","F1"};
dtBase = New Table("Base");
dtStacked = {};
For( i = 1, i <= N Items( my_list ), i++,
dt << Row Selection( Select where( (:Freq==my_list[i]), Current Selection( "Extend" )) );
dt << Select Columns( [19] );
Insert Into( dtStacked, dt );
dtBase << Concatenate( dtStacked );
Close( dtStacked, nosave );
);dtBase is empty.
Insert Into() doesn't do what it appears you think it does.
In your code it would insert the data table reference dt into the dtstacked list repeatedly. It doesn't have anything to do with the selected rows or columns.
You'll need to create a new data table of the selected rows and columns using Subset() and insert that reference into dtstacked and then concatenate them.
Though, that doesn't seem necessary. Since you're just extending the selection each time through the loop at the very end you could do a subset of the selected rows and column and get the same result as your concatenated data table.
To not concatenate, but rather to add new columns then simply use the Update platform.
Here is a code that seems to work, manually. Now I will try to do it in a loop:
dt << Row Selection( Select where( (:Stat == "selection1"), Current Selection( Extend )) ); dt << Select Columns( [15, 19] ); dt << Row Selection( Select where( (:Stat == "selection2"), Current Selection( Extend )) ); dt << Select Columns( [15, 19] ); dt << Subset( ( Selected Columns ), Output Table Name( "Subset_1_2" ) );