cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
student
Level III

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? 

 

 

15 REPLIES 15
student
Level III

Re: Filter by row, stack columns?

No, the above code still concatenate. I'll try "update" command.

student
Level III

Re: Filter by row, stack columns?

I apologize for the many posts. I am still stuck. Right now all what I have is this script that results in two tables, each having one column that I am interested in. I am able to manually copy and paste one column from table 1 to table 2, but can't do it automatically.

 

dt << Row Selection( Select where( (:Freq == "F0"), Current Selection( Extend )) );
dt << Select Columns( [15,19] );
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] );
dt << Subset( ( Selected Columns ), Output Table Name( "F1" ) );
txnelson
Super User

Re: Filter by row, stack columns?

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));
Jim
student
Level III

Re: Filter by row, stack columns?

Thanks, that was correct! Only thing remaining is how to put it in a for loop. Here is my trial:

 

For(i=1, i<=NItems(freq_list), i++,
	dt << clear select;
	dt << Row Selection( Select where( (:Freq == (freq_list[i])), Current Selection( Extend )) );
	dt << Select Columns( [15,19] );
	dt << Subset( ( Selected Columns ), Output Table Name( freq_list[i] ) );
);

But this produces two identical tables even though I clear the selection at the start of each loop.

txnelson
Super User

Re: Filter by row, stack columns?

Rethinking of what I am guessing is your desired final table output, I suggest that you take a look at

     Tables=>Split

The example below splits by the :Sex column, it would be your :Freq column, and the Split columns are Height and Weight, which would be your 15 and 19 columns.

The output creates pairs of columns for each of the Split By column values

Names Default To Here( 1 );
dt = open("$SAMPLE_DATA\big class.jmp");

// Split data table
// → Data Table( "Untitled 66" )
Data Table( "big class" ) << Split(
	Split By( :Sex ),
	Split( :height, :weight ),
	Remaining Columns( Drop All ),
	Sort by Column Property
);

split.PNG

Jim
student
Level III

Re: Filter by row, stack columns?

That is actually what I wanted, thanks again!