cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
h_lazar
Level I

get rows where returning empty matrix

I have a data table that I am trying to manipulate. I am using get rows where function to find where the first column equals a string, let's call it "aaa". When I use the software to do this, it works fine and two rows are selected, row 1 and row 2240. When I try to script this, the result is an empty matrix.

Here is the script I am using:


Names Default To Here( 1 );


dtx = Current Data Table();


noRows = N Rows( dtx );


ddd = dtx << Get Rows Where( Column( dtx, 1 ) == "aaa" );


and the result is


[](0, 1)


note that this returns a 1


Column( dtx, 1 ) [1] == "aaa"


Does anyone have any idea what I am doing wrong?

thanks in advance

Heather

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: get rows where returning empty matrix

I looks like Get Rows Where wants a simpler argument, try one of these


dtx=open("$sample_data/big class.jmp");


c=column(dtx,3);


dtx<<get rows where( dtx:c == "F" );


or


dtx=open("$sample_data/big class.jmp");


dtx<<get rows where( dtx:sex == "F" );


the odd looking returned value, [](0, 1), is JMP's empty array of 0 rows and 1 column.  the two examples return more rows, of one column:

[1, 2, 3, 4, 5, 9, 10, 11, 16, 17, 18, 19, 20, 28, 29, 35, 36, 38]

Craige

View solution in original post

4 REPLIES 4
Craige_Hales
Super User

Re: get rows where returning empty matrix

I looks like Get Rows Where wants a simpler argument, try one of these


dtx=open("$sample_data/big class.jmp");


c=column(dtx,3);


dtx<<get rows where( dtx:c == "F" );


or


dtx=open("$sample_data/big class.jmp");


dtx<<get rows where( dtx:sex == "F" );


the odd looking returned value, [](0, 1), is JMP's empty array of 0 rows and 1 column.  the two examples return more rows, of one column:

[1, 2, 3, 4, 5, 9, 10, 11, 16, 17, 18, 19, 20, 28, 29, 35, 36, 38]

Craige
h_lazar
Level I

Re: get rows where returning empty matrix


dtx=open("$sample_data/big class.jmp");


c=column(dtx,3);


dtx<<get rows where( dtx:c == "F" );


This did work, thank you both.

H

ms
Super User (Alumni) ms
Super User (Alumni)

Re: get rows where returning empty matrix

A comparison of a Column object with a string will return always return false. In certain cases (or in general?) JMP must be expliticly told that you refer to a Column or to the Column values (I remember there has been a good thread about this maybe a little confusing difference but I can't find it now...)

You can access data with indices (as you showed above with Column( dtx, 1 ) [1] == "aaa"). In functions like Get Rows Where() that basically iterate through all column values, each value can be accessed with either of the below:

1) Column(dtx,1)[] == "aaa" // Note the empty brackets

2) As Column(dtx,1) == "aaa"

3) Or simplest with scoping colon as C Hales showed above

Craige_Hales
Super User

Re: get rows where returning empty matrix

cool.  I didn't read the original question closely enough, and I'd forgotten about the empty [] anyway.

Craige