cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
MeanChris
Level III

Step by Step Row "list" building: Get All Rows, then Get Rows Where X, then Get Rows Where Y (and X)

I'm trying to understand working with objects that are containers of rows.  Even that description may be incorrect.

What is "FilteredRows" in this context?

dt = Current Data Table();
FilteredRows = dt << get rows where( :Date == 12May2025 );
Show( N Rows( FilteredRows ) );

To back up slightly, is there a JSL command to set an object to ALL rows in a datatable?  Or is that never necessary?

The closest I can find that avoids 'Select All Rows' is:

AllRows = dt << get rows where(1);

Feels like cheating though.

More importantly, I'd like to be able to apply additional filters to a subset of rows

This does not work, but conveys the intent:

XFilteredRows = dt << get rows where( :X == 42 );
XYFilteredRows = XFilteredRows << get rows where(:Y ==1.21);

Yes, I can do both in one line

XYFiteredRows = dt << get rows where(:X==42 & :Y==1.21);

However I plan to use this in a For Each Row loop, where X removes 99% of the rows, and I'll need to subsequently filter more parameters independently, i.e. rows that meet XY, and rows that meet XZ and rows that meet X but not Y, etc...

I believe it will be faster on large tables to keep the X filtered rows. 

On a related note, one result I'm trying to get is very similar to the 'Group By' result, but with a custom formula.  

JSL of a column formula:

Col Mean( :Parameter, :X )

'Group By' is very convenient for created column formula from built in functions, but when I want to do more complex math I don't know how to achieve the same grouping effect.

 

1 ACCEPTED SOLUTION

Accepted Solutions
hogi
Level XIII

Re: Step by Step Row "list" building: Get All Rows, then Get Rows Where X, then Get Rows Where Y (and X)

The "container" is a (1 dimensional) "matrix".

you can also create a matrix  manually:

myRows= Matrix ({1,2,3})

myRows = 1::3

myRows = [1, 2, 3]

 

There are 2 ways to intersect (and other set operations like union, difference)

a) using associative arrays

aa1 = associative array (myRows1);
aa2 = associative array (myRows2);

aa1 << intersect(aa2);
// aa1 << remove(aa2); list of rows = aa1 << get keys; rows= matrix(list of rows);

hogi_0-1762465541044.png

 

b) [new in JMP19]: using lists

list1 = as list (myRows1);
list2 = as list (myRows2);

list of rows = set intersect(list1, list2);
list of rows = set intersection(list1, list2);
//list of rows = set difference(list1, list2);
rows= matrix(list of rows);

hogi_1-1762465805149.png

 

Intersections for Matrices? I guess: no

View solution in original post

2 REPLIES 2
hogi
Level XIII

Re: Step by Step Row "list" building: Get All Rows, then Get Rows Where X, then Get Rows Where Y (and X)

The "container" is a (1 dimensional) "matrix".

you can also create a matrix  manually:

myRows= Matrix ({1,2,3})

myRows = 1::3

myRows = [1, 2, 3]

 

There are 2 ways to intersect (and other set operations like union, difference)

a) using associative arrays

aa1 = associative array (myRows1);
aa2 = associative array (myRows2);

aa1 << intersect(aa2);
// aa1 << remove(aa2); list of rows = aa1 << get keys; rows= matrix(list of rows);

hogi_0-1762465541044.png

 

b) [new in JMP19]: using lists

list1 = as list (myRows1);
list2 = as list (myRows2);

list of rows = set intersect(list1, list2);
list of rows = set intersection(list1, list2);
//list of rows = set difference(list1, list2);
rows= matrix(list of rows);

hogi_1-1762465805149.png

 

Intersections for Matrices? I guess: no

MeanChris
Level III

Re: Step by Step Row "list" building: Get All Rows, then Get Rows Where X, then Get Rows Where Y (and X)

hogi,

You've rescued me again.  Thanks!

One clarification, I used your syntax

list of rows = set intersect(list1, list2);

initially and it turned blue so I thought it was okay, but odd that it didn't capitalize.  Then I looked it up in scripting guide and realized it was "Set Intersection".   Now I'm good to go.  Cheers!

Recommended Articles