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
Neo
Neo
Level VI

Filter row item by comparing multiple parameters related the item using a script

I have attached example data from which I need to extract the row for which the yield is minimum for a given PartID. I would like to do this using a script.

This I need to do for each PartID and then have a table with only the filtered rows (i.e. [PartID], [Parameter] [(min-) Yeild]).

SampleData.PNG

Note, I have deliberately put identical yield for part C as I may have similar data and would like to handle such using the script. I am on JMP13.

Thanks.

When it's too good to be true, it's neither
1 ACCEPTED SOLUTION

Accepted Solutions
Neo
Neo
Level VI

Re: Filter row item by comparing multiple parameters related the item using a script

Ok figured it out, the corrected script is (it should be theMin = Minimum( :Yield) inside the for loop as well)

Names Default To Here( 1 );
dt = Current Data Table();

Summarize( dt, thePartID = by( :PartID ), theMin = Minimum( :Yield) );

dt << clear select;

For( i = 1, i <= N Items( thePartID ), i++,
	dt << select where(
		:PartID == thePartID[i] & :Yield == theMin[i],
		current selection( "extend" )
	)
);

dtSelected = dt << subset( selected rows(1), selected columns(0));

  

When it's too good to be true, it's neither

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: Filter row item by comparing multiple parameters related the item using a script

Here is one way to handle your request:

Names Default To Here( 1 );
dt = Current Data Table();

Summarize( dt, thePartID = by( :PartID ), theMin = Minimum( :Parameter ) );

dt << clear select;

For( i = 1, i <= N Items( thePartID ), i++,
	dt << select where(
		:PartID == thePartID[i] & :Parameter == theMin[i],
		current selection( "extend" )
	)
);

dtSelected = dt << subset( selected rows(1), selected columns(0));
Jim
Neo
Neo
Level VI

Re: Filter row item by comparing multiple parameters related the item using a script

Thanks. Running your script directly gives me the following error

Column Must be Numeric in access or evaluation of 'Parameter' , :Parameter/*###*/

In the following script, error marked by /*###*/
dt = Current Data Table();
Summarize( dt, thePartID = by( :PartID ), theMin = Minimum( :Parameter/*###*/ ) );
dt << clear select;
For( i = 1, i <= N Items( thePartID ), i++,
	dt << select where(
		:PartID == thePartID[i] & :Parameter == theMin[i],
		current selection( "extend" )
	)
);
dtSelected = dt << subset( selected rows( 1 ), selected columns( 0 ) );

 

Perhaps the third line should be 

Summarize( dt, thePartID = by( :PartID ), theMin = Minimum( :Yield) );

Anyway running the script give me with the above line. 

Empty()

I have attached the data table with script inside. 

When it's too good to be true, it's neither
Neo
Neo
Level VI

Re: Filter row item by comparing multiple parameters related the item using a script

Ok figured it out, the corrected script is (it should be theMin = Minimum( :Yield) inside the for loop as well)

Names Default To Here( 1 );
dt = Current Data Table();

Summarize( dt, thePartID = by( :PartID ), theMin = Minimum( :Yield) );

dt << clear select;

For( i = 1, i <= N Items( thePartID ), i++,
	dt << select where(
		:PartID == thePartID[i] & :Yield == theMin[i],
		current selection( "extend" )
	)
);

dtSelected = dt << subset( selected rows(1), selected columns(0));

  

When it's too good to be true, it's neither
txnelson
Super User

Re: Filter row item by comparing multiple parameters related the item using a script

Sorry for the misdirection......I made up a data table to test the script on, and in error, I used the :Parameter name as the target column, instead of the :Yield column.

Jim