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
PioJesudoss
New Member

In a data frame Filter column based on another column that contains the column name

Hello Folks,

I have attached a data set. In the data set, I have column called Parameter that contains the name of the columns that are in the data set. I want to first filter the column that corresponds to each unique column name that is present in the Parameter column and then join it to the subset column that I have created and create a variability chart. At this moment I have 2 unique parameters in the Parameter column and this can vary week on week, so I would like it to be parameterized.  I have below some of the code that I have done. Any help would be appreciated

Thanks

Pio 

 

dt_2 = Data Table( "jmp_question_T_V0" ) << Summary(
Group( :Parameter ),
Freq( "None" ),
Weight( "None" )
);
 
lst = column(dt_2,1) << GetAsMatrix();
close(dt_2,no save);
 
subset_cols = {:Name("PRA"), :Name("WA"), :Name("CH"), :Name("WA_D"),
:Name("CH_D"),:Name("SL_T"),:Name("TST_DATE"),:Name("IL_M"),:Name("QTY"),
:Name("W"),:Name("Parameter"),:Name("h_t_d")};
 
length (lst)
 
iparam = 1
while(iparam=length(lst)) {
print(lst[iparam])
dt=dt_1
 
dt_1 << select where (:Parameter == lst[iparam])  //works
dt<<subset(output table) //works
dt<< subset(all rows, columns(subset_cols))
 
dt_param<<Subset((dt_1 << select where (:Parameter == lst[iparam])), columns(subset_cols))

 

1 REPLY 1
jthi
Super User

Re: In a data frame Filter column based on another column that contains the column name

The script you have provided doesn't work as it is missing ; and using incorrect syntax for while loop. If you want to get unique values from a character column, you can use Summary table, Summarize function or Associative Array. I'm not exactly sure what you wish to do as you only provided single .csv file.

Names Default To Here(1);

dt = Current Data Table();

params = Associative Array(Column(dt, "Parameter")) << get keys;

If you wish to create separate subsets based on the Parameter column, you can just use that as a subset by column

jthi_0-1736522129795.png

Names Default To Here(1);

dt = Current Data Table();

mycols = {"W", "W_s", "R_rd1", "R_rd1_s"};

dt_subsets = dt << Subset(By(:Parameter), Selected Rows(0), Columns(mycols));

Or looping

Names Default To Here(1);

dt = Current Data Table();

params = Associative Array(Column(dt, "Parameter")) << get keys;
mycols = {"W", "W_s", "R_rd1", "R_rd1_s"};

dts = {};

For Each({param}, params,
	cur_rows = dt << get rows where(:Parameter == param);
	dt_subset = dt << Subset(Rows(cur_rows), Selected Rows(0), Columns(mycols));
	Insert Into(dts, dt_subset);
);

You could also select the rows but it is usually unnecessary

-Jarmo