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
Theresa
Level IV

How to select rows with 2 different data table with matched column

&*script below don't work could you help to debug and send me a workable script? I want to realize the function that "select all rows" in dt which matched column: name in dt1.

dt = Open( "$SAMPLE_DATA/BIG CLASS.JMP" );
dt1 = dt << Subset( Columns( Name ), Output Table Name( "1" ) );
dt1 << Delete Rows( 15 :: 40 ); // I want to relize the function of "select all rows that (dt:name==dt1:name) dt << Select where( With(dt1), By Matching Columns(name==name), );
;
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to select rows with 2 different data table with matched column

Here are 3 different ways to do this.....and I am sure others may have other ways to do this

names default to here(1);

dt = Open( "$SAMPLE_DATA/BIG CLASS.JMP" );
dt1 = dt << Subset( Columns( Name ), Output Table Name( "1" ) );
dt1 << Delete Rows( 15 :: 40 ); 

// Method one, read a name in dt1 and select it in dt, repeat 
// for all rows in dt1

dt << clear rowstates;

For(i=1,i<= nrows(dt1),i++,
	dt << select where(dt:name == dt1:name[i], current selection("extend"));
);

// Method 2, extract names from dt1 into a list, and then
// compare against the list for the 

dt << clear rowstates;

nameList = dt1:name << get values;
dt << select where(contains(nameList,:name));

//Method 3, Update dt with dt1 and select matching rows
// this method would be the fastest on large data tables

dt << clear rowstates;

// add a column to use as a selector
dt1 << New Column( "selector", set each value( 1 ) );

dt << Update( With( dt1 ), Match Columns( :name = :name ) );
dt << select where( :selector == 1 );
dt << delete columns( "selector" );
dt1 << delete columns( "selector" );
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: How to select rows with 2 different data table with matched column

Here are 3 different ways to do this.....and I am sure others may have other ways to do this

names default to here(1);

dt = Open( "$SAMPLE_DATA/BIG CLASS.JMP" );
dt1 = dt << Subset( Columns( Name ), Output Table Name( "1" ) );
dt1 << Delete Rows( 15 :: 40 ); 

// Method one, read a name in dt1 and select it in dt, repeat 
// for all rows in dt1

dt << clear rowstates;

For(i=1,i<= nrows(dt1),i++,
	dt << select where(dt:name == dt1:name[i], current selection("extend"));
);

// Method 2, extract names from dt1 into a list, and then
// compare against the list for the 

dt << clear rowstates;

nameList = dt1:name << get values;
dt << select where(contains(nameList,:name));

//Method 3, Update dt with dt1 and select matching rows
// this method would be the fastest on large data tables

dt << clear rowstates;

// add a column to use as a selector
dt1 << New Column( "selector", set each value( 1 ) );

dt << Update( With( dt1 ), Match Columns( :name = :name ) );
dt << select where( :selector == 1 );
dt << delete columns( "selector" );
dt1 << delete columns( "selector" );
Jim
ezorlo
Level IV

Re: How to select rows with 2 different data table with matched column

this is really nice! I used method 1.

I needed to copy-paste the file path of my data table for this to work. i couldnt figure out how to change the working directory so that I could just type in the file names without the whole path.

 

Theresa
Level IV

Re: How to select rows with 2 different data table with matched column

thank you so much

Recommended Articles