cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar

Stacking and Concatenating

Started ‎11-08-2022 by
Modified ‎11-08-2022 by
View Fullscreen Exit Fullscreen

This demonstration shows two more commands from the Tables menu-- the Stack and Concatenate commands. So in section of the journal, I'm going to click on Cure Time Data again. And the organization of this table is that each cure time sample has its own separate column. And if I wanted to, for example, compare the averages of the five different cure times, that kind of analysis would want the data structure to-- JMP would want the data structured so that I had one column that indicated which cure time it was and one column that indicated the actual numeric values. And so in order to rearrange the table that way, we can use the Stack command. And that Stack command will convert from what we might call a wide table, although this one is not very wide, to a tall table. And I'm going to do this interactively and then grab the script from that source script that JMP creates. So I'll go to the Tables menu and select Stack. And I'll select Cure Time through Cure Time and click Stack Columns. I'm going to leave most of the default options checked. But I will add an output table name-- I'll call it Stacked Cure Time Data. And then I want to provide the new column name. So the stacked data column will be the actual cure time values. So I'll write Cure Time for that. And the source label column-- this is what I am going to call the column that will contain what previously were column headers. So I'll call that one Sample. And then I'll click OK. And now instead of a table with six columns and rows, I have a table with three columns and rows. And by default, JMP kept this column that wasn't involved in the stack. That is an option in the dialog that you can uncheck if you didn't want to keep that. So now if I did want to perform an analysis of variance to compare the means of each of these, I have that sample column that would be in the X analysis role in the Oneway platform. But I want to grab this source script. So I'm going to right click on that and select Edit. And I'll just select the contents. You can also use the keyboard shortcut of Ctrl+A. Or you could right click. It's a small script, so I just highlighted it manually. And I'm going to copy that, which again, you can use your keyboard shortcuts or right click. And I'll cancel out of that window. And I'm doing this because I have a table called Historical Cure Time Data that I'll open in just a moment that is already formatted in this stacked fashion. And if I wanted to put these two tables together into one table, they either both need to be in this tall format or they both need to be in the wide format. So I'm going to go ahead and-- I just got the script for the stacked cure time data. I'm going to close that without saving and I'm going to open a new Script Editor window-- again, that's Ctrl+T for the keyboard shortcut. And I'll Ctrl+V to paste that. At the start of this, I want to give this the object reference for this new stacked data table. And I want to store that in a variable. So I'm to call this one dtStacked. And I'll assign it the result of the script I just pasted. And I'll add a semicolon. Now let me go ahead and open up the Historical Cure Time Data by clicking that script in the journal. So again, this is in that tall format. If I wanted to keep the wider format when I put these data together, there's a command in the Tables menu called split, which does the opposite of stack. But since I already have stacked or gotten the script for the newer cure time data, I'm going to stack that one. And then I want to concatenate the newer data to the historical cure time data. And concatenate with tables is simply a vertical append. So with both windows open, I'm going to come back to the script and go to a new line. And although I'm not going to work with this new data table any further, I will go ahead and store the reference in a variable called dtUpdated. And I'll sign that the result of the historical cure time data receiving the concatenate message. So I'm going to type data table and then the double quotation marks Historical Cure Time. And perhaps you can see why this syntax is preferable to current data table in a situation where I have two data tables open. And I'll type the Send operator, concatenate, which again is coming from the Tables menu. And then in parentheses, I will put the name of the variable storing the newer cure time data after it's been stacked. So dtStacked is the argument to concatenate. And there are many other arguments you can supply to concatenate. If you go to the tables menu and select concatenate, you can see in that dialog what those options are. In fact, you could do this interactively, use some of those options, and then get that source script. But for our purposes, I'm going to keep it simple and simply supply the table that I am appending to the historical cure time. So the script stacks the newer cure time data table, the one we've been working with so far, and then appends that to the historical cure time, which is already in that tall format. So I'll run the entire script and we get the stacked cure time data as an intermediate step. In practice, your script would probably want to close this data table once we had the data collected in our new, untitled data table. And again, the concatenate-- we could have provided that output table name in a more complete script. So here you've just seen a couple more examples from the tables menu, and also the idea that we can grab that source script and then modify it or adapt it or insert it into another script that we're working on.