Filter by row, stack columns?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?
ScriptingRe: Filter by row, stack columns?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;
Re: Filter by row, stack columns?(Hit accept as solution by mistake)
Thanks but I don't want to delete selected rows. I can take care of that, but how would I append the selection when using Stack?Re: Filter by row, stack columns?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.
Re: Filter by row, stack columns?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:
- Before starting the repeating Stack instances, create an empty Base data table that will end up having all of the stacked tables concatenated to it
dtBase = New Table("Base");
- Then for each of the stacked tables you create,
- Delete the rows you do not want from the stacked data table
- Concatenate the Stacked table to the Base table
dtBase << Concatenate( dtStacked );
- Delete the Stacked table
Close( dtStacked, nosave );
Re: Filter by row, stack columns?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.