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
ALopez
Level III

How to use a list to select rows with an specific value

Hi I am trying to use a list of Names that populate a column to select the matching rows of another column (in another Table) in order to subset the table and generate several different subsets.

Getting the Names/Values from the first column is no problem but I cannot find the correct syntax for the loop.

dt4 = Current Data Table();
uniqueVals = {"2021_file1_T1", "2021_file1_T2"};

tableList= {};

For(i=1, i< N Items(uniqueVals), i++,
dt4 << select where( As Column("Type") == [i] ) );
dt4 << Select Columns (all);
newdt[i] = dt4 << Subset( Selected columns );
Insert Into(tableList, Data Table(newdt[i]));
dt4 << Clear Column Selection();
dt4 << Clear Select();
);// end of For

I think that my basic logic is OK  since this code works very well

dt4 << select where( As Column("Type") =="2021_file1_T2");
dt4 << Select Columns(all);
dt4 << Subset (Selected columns);

But I cannot figure out how to pass [i] to the "Select Where".  Attached is a simplified test table.
I will appreciate any hints/ solution/suggestions.

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to use a list to select rows with an specific value

You were pretty close in getting done what you want.  Below is my rework of your code.  Please note that your tableList list is redundant with the newdt list that you are referencing.

dt4 = Current Data Table();
uniqueVals = {"2021_file1_T1", "2021_file1_T2"};

//tableList = {};
newdt = {};

For( i = 1, i <= N Items( uniqueVals ), i++,
	dt4 << select where( As Column( "Type" ) == uniqueVals[i] );
	dt4 << Select Columns( all );
	newdt[i] = dt4 << Subset( Selected columns );
	//Insert Into( tableList, Data Table( newdt[i] ) );
	dt4 << Clear Column Selection();
	dt4 << Clear Select();
);
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: How to use a list to select rows with an specific value

You were pretty close in getting done what you want.  Below is my rework of your code.  Please note that your tableList list is redundant with the newdt list that you are referencing.

dt4 = Current Data Table();
uniqueVals = {"2021_file1_T1", "2021_file1_T2"};

//tableList = {};
newdt = {};

For( i = 1, i <= N Items( uniqueVals ), i++,
	dt4 << select where( As Column( "Type" ) == uniqueVals[i] );
	dt4 << Select Columns( all );
	newdt[i] = dt4 << Subset( Selected columns );
	//Insert Into( tableList, Data Table( newdt[i] ) );
	dt4 << Clear Column Selection();
	dt4 << Clear Select();
);
Jim
ALopez
Level III

Re: How to use a list to select rows with an specific value

Hi @txnelson, So close yet so far.... Thank you very much for your help.