Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted

How to write a "for" loop that includes a function to name columns

Hi!

I have a data set (dt) that gets additional data over time; the time periods are listed as days in the column :elapsed time.

I have already taken this data and split it so that each new day in the :elapsed time column creates a new column in a second sheet. The number of elapsed days will grow over time; so the number of columns in the new sheet will also grow. I am planning to re-run this script as we gather more data so I can see the trend over time.

I can't seem to figure out how to make a series of columns that show the difference between the various elapsed times and the original time, though.

 

 

 

//Taking the "dt" table and splitting the elapsed time column up into multiple columns in a new sheet 


straightness = dt << split(
Split by (:Elapsed Time ),
Split (:Straightness ),
Group (:Rod NUmber ),
Remaining columns (select (:Rod NUmber | :Type | :Location | :Study) ),
Output Table ("Straightness")
);

//Using the hidden "dt" table, we are figuring out which days exist as options in the "elapsed time" column


summarize (dt, sample = by (:elapsed time) ); new columns = N Items (sample);
//In the new spreadsheet, where each of these days is a new column, this "for" loop should generate a new column for each non-zero elapsed time value


for( i=1, i<= new columns, i++, col = num(sample [i]); straightness<< New Column (sample [i] || " Days", formula (eval(column (13+i+new columns)) - :Name("0")) );

 

For example, I current have three days' worth of data, so I have sample = {0, 1, 2}. I want to make two new columns, column "1 day" and column "2 day", each which contains the data from that respective day minus the data from day 0.

But as my data grows and I have more data, for example sample = {0, 1, 2, 3, 4, 5}, I will want to make 5 new columns, each with its respective data and naming scheme.

 

Thank you!!

1 REPLY 1
Highlighted

Re: How to write a "for" loop that includes a function to name columns

//Taking the "dt" table and splitting the elapsed time column up into multiple columns in a new sheet

straightness = dt << split( Split by (:Elapsed Time ), Split (:Straightness ), Group (:Rod NUmber ), Remaining columns (select (:Rod NUmber | :Type | :Location | :Study) ), Output Table ("Straightness"));

//Using the hidden "dt" table, we are figuring out which days exist as options in the "elapsed time" column

summarize (dt, sample = by (:elapsed time) );
new columns = N Items (sample);

//In the new spreadsheet, where each of these days is a new column, this "for" loop should generate a new column for each non-zero elapsed time value

for( i=1, i<= new columns, i++, col = num(sample [i]); straightness<< New Column (sample [i] || " Days", formula (eval(column (13+i+new columns)) - :Name("0")) );

^^Fixed the script because it pasted weird 

Article Labels

    There are no labels assigned to this post.