cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
CitizenNo3
Level II

Equivalent of get rows where for multiple arrays

Hello, 

 

This seems like a quite basic question, but I'm likely using the wrong search terms because I haven't found a good answer.

 

I have a script where initially I was just making a list of strings (file paths) and could use them in sequential order without issue. As the scope expanded, I now need to do filtering based on criteria in two other lists of the same length that were created at the same time. My brain still works in data tables, and in a data table (or SQL) format this would be an easy thing to do. Creating a hidden data table could be a viable option, but I'd like to better understand working with different data structures and changing my code to use another dt seems messy. 

 

This seems like an application for associative arrays, but I'm struggling to correctly create the array and the scripting guide and scripting index hasn't been illuminating. Can someone point me in the right direction or suggest a data structure that would make more sense for what I'm now trying to do? Or would a hidden table actually be the best option?

 

Also note that in this example I have three individual lists. In my current application each list is contained in its own list where List_A[1] corresponds to List_B[1], etc, but I'm iterating through the parent lists.

 

Thank you!

Names Default To Here( 1 );
//example data is in dt, my data isn't
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

//this is more or less the structure of the data that I have 
sex_list = dt:sex << get values;
height_list = dt:height << get values;
weight_list = dt:weight << get values;

//this is what I would do if I had the data in a dt
output = dt:weight[dt << get rows where(and(:age == 13, :sex == "M"))];
show(output);

//how to do this with the data in a structure with no dt? what structure would be appropriate? 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Equivalent of get rows where for multiple arrays

JMP data tables are easy to query and they are pretty fast (depending on your query) so I would most likely just use private or invisible data table.  If you really want to use associative array, I think you would have to create quite a lot of unique keys such as "13_M" to indicate age == 13 and sex == "M".

-Jarmo

View solution in original post

Craige_Hales
Super User

Re: Equivalent of get rows where for multiple arrays

The loc() function to find items in a list or matrix. Use the associative arrays to intersect several lists of indexes. Re: Quick way to compare two lists (uncommon elements)? 

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

name_list = dt:name << get values;// a list
sex_list = dt:sex << get values;// a list
age_list = dt:age << get values;// a matrix
weight_list = dt:weight << get values;

age_rows = Loc( 13 <= age_list <= 14 );
sex_rows = Loc( sex_list, "M" );

// intersection of those   https://community.jmp.com/t5/Discussions/Quick-way-to-compare-two-lists-and-identify-the-uncommon/m-p/5811

intersect = Associative Array( age_rows );// uses two associative arrays
intersect << intersect( Associative Array( sex_rows ) ); // perform the intersection
intersect = intersect << getkeys; // get the answers

For Each( {key}, intersect, Write( Eval Insert( "\!n^name_list[key]^ \!t^age_list[key]^ \!t^sex_list[key]^ \!t^weight_list[key]^" ) ) );
/*
JOHN 	13 	M 	98
JOE 	13 	M 	105
MICHAEL 	13 	M 	95
DAVID 	13 	M 	79
FREDERICK 	14 	M 	93
ALFRED 	14 	M 	99
HENRY 	14 	M 	119
LEWIS 	14 	M 	92
EDWARD 	14 	M 	112
CHRIS 	14 	M 	99
JEFFREY 	14 	M 	113
*/
Craige

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Equivalent of get rows where for multiple arrays

JMP data tables are easy to query and they are pretty fast (depending on your query) so I would most likely just use private or invisible data table.  If you really want to use associative array, I think you would have to create quite a lot of unique keys such as "13_M" to indicate age == 13 and sex == "M".

-Jarmo
Craige_Hales
Super User

Re: Equivalent of get rows where for multiple arrays

The loc() function to find items in a list or matrix. Use the associative arrays to intersect several lists of indexes. Re: Quick way to compare two lists (uncommon elements)? 

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

name_list = dt:name << get values;// a list
sex_list = dt:sex << get values;// a list
age_list = dt:age << get values;// a matrix
weight_list = dt:weight << get values;

age_rows = Loc( 13 <= age_list <= 14 );
sex_rows = Loc( sex_list, "M" );

// intersection of those   https://community.jmp.com/t5/Discussions/Quick-way-to-compare-two-lists-and-identify-the-uncommon/m-p/5811

intersect = Associative Array( age_rows );// uses two associative arrays
intersect << intersect( Associative Array( sex_rows ) ); // perform the intersection
intersect = intersect << getkeys; // get the answers

For Each( {key}, intersect, Write( Eval Insert( "\!n^name_list[key]^ \!t^age_list[key]^ \!t^sex_list[key]^ \!t^weight_list[key]^" ) ) );
/*
JOHN 	13 	M 	98
JOE 	13 	M 	105
MICHAEL 	13 	M 	95
DAVID 	13 	M 	79
FREDERICK 	14 	M 	93
ALFRED 	14 	M 	99
HENRY 	14 	M 	119
LEWIS 	14 	M 	92
EDWARD 	14 	M 	112
CHRIS 	14 	M 	99
JEFFREY 	14 	M 	113
*/
Craige
CitizenNo3
Level II

Re: Equivalent of get rows where for multiple arrays

Thanks Craige, Jarmo! So it is definitely possible to do with arrays, but it takes a few steps, so it seems like JSL is more designed to use an invisible/private table in a case like this (hence why I wasn't finding obvious answers).