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

How to add data values to a table in a for loop using Select Columns Where to make a new overall data table of target data

For( date = date_array << First, !Is Empty( date ), date = date_array << Next( date ), //looping through date_array's keys is clunky but done this way in JMP
		dt << Select Columns( :Timepoint, :Target Channel, :Run date ), Where(:Timepoint == date);
		dt << Subset( ( Selected Rows ), Output Table Name( "Subset" ));
);

I wish to add, progressively, through each iteration of a for loop, data specified by a column criterion (:Timepoint == LBCM) and combine it into a combined data table at the end, when the loop is done, and display the result.

 

As of now it doesn't add anything anywhere; I end up with no new data table at all.

 

I have all of this inside another for loop, as well, based off of a sample ID but I think adding that here would only overcomplicate things for now.

 

All the other examples I have found in the JMP Community Forums are very complicated, or so they seem, building arrays of data and transferring them to data tables or things like that. I wish for the solution here to be as simple as possible. Of course, I will contribute to the conversation as replies come in, but as of now I am just flat out stuck.

 

Thank you for your help,

Mike

5 REPLIES 5
txnelson
Super User

Re: How to add data values to a table in a for loop using Select Columns Where to make a new overall data table of target data

Take a look at 

dt << add rows(n);

to add new rows as needed

Jim
jthi
Super User

Re: How to add data values to a table in a for loop using Select Columns Where to make a new overall data table of target data

I'm not 100% sure what you want to do here so I'm guessing a little

 

These two rows seems like there might be some issues:

dt << Select Columns( :Timepoint, :Target Channel, :Run date ), Where(:Timepoint == date);
dt << Subset( ( Selected Rows ), Output Table Name( "Subset" )););

You can combine the columns you want inside the subset command and selecting rows can be done with << Select Where (seems like you are missing Select).

dt << Select Where(:Timepoint == date);
dt << Subset(Columns({"Timepoint", "TargetChannel"}), Selected Rows, Output table name("Subset"));

Also if you would prefer to first select the columns which you want to subset, you will have to add Selected Columns inside Subset command

dt << Subset(Output table name("Subset"), Selected Rows, Selected Columns);
-Jarmo
mostarr
Level IV

Re: How to add data values to a table in a for loop using Select Columns Where to make a new overall data table of target data

Thanks for this, Jarmo. So is your code mostly an efficiency gain or a bona fide functionality gain?

It doesn't work outright for me, but I have to say that I have all of this in another for loop (or two):

For( i = 1, i <= N Items( IDs ), i++,
	ID = IDs[i];
	date_array = Associative Array( {"date1", "date2", "date"}, {{}, {}, {}} );
	For( date = date_array << First, !Is Empty( date ), date = date_array << Next( date ), //looping through date_array's keys is clunky but done this way in JMP			
		dt << Select Where(:Timepoint == date);
		dt_ld4 << Subset(Columns({"Timepoint", "Target Channel"}), Selected Rows, Output table name("Subset"));
//...
););

The computer seems to think quite a bit upon execution but nothing shows up on the screen. I have to note that all of this code is anonymized so there's possibility for spelling mistakes and transcription errors, as well as possibility of getting confused with earlier versions of what was written. I guess it's safe to assume approximate similarities can be made...

 

I don't know if these two lines should be inside the loops or outside one of them, or if I need both loops at this point in time. I need to take a deep hard look at the script one more time.

 

I'm also discussing a few separate topics regarding this bit of code in separate posts. Could someone senior let me know if that is acceptable etiquette, or if it would be preferable to prioritize the code chunk into one post and discuss the separate topics in the single post, or whether either way is alright?

 

Muchos Gracias,

Michael

jthi
Super User

Re: How to add data values to a table in a for loop using Select Columns Where to make a new overall data table of target data

Selecting Columns part is maybe a very small efficiency gain, but mostly it just makes the code easier to read (in my opinion). 

 

Have you tried adding debugging prints inside loops to see if there is anything to subset:

 

For(i = 1, i <= N Items(IDs), i++,
	ID = IDs[i];
	date_array = Associative Array({"date1", "date2", "date"}, {{}, {}, {}});
	For(date = date_array << First, !Is Empty(date), date = date_array << Next(date),		
		dt << Select Where(:Timepoint == date);
		Show(N Items(dt << Get Selected Rows));
		dt_ld4 << Subset(Columns({"Timepoint", "Target Channel"}), Selected Rows, Output table name("Subset"));
	);
);

I added Show(N Items(dt << Get Selected Rows)); which should tell you if any rows have been selected. Also I wouldn't feel comfortable using ID as variablename if you have similarly named column (it might work, not sure, but I do avoid such names just to be sure). I would replace it with currentID or something.

 

I would think that at this point, it could maybe be easier if we had one topic in which we could try to help you solve this issue part by part. One thing that would help us a lot would be having an example dataset. The dataset doesn't have to be large, can be anonymized or completely fake data, but it should still be realistic (column data types same, possibility to test different cases).

 

-Jarmo
txnelson
Super User
 
Jim