Subscribe Bookmark RSS Feed

JSL - Combining Columns from a table for a function

drblove

Contributor

Joined:

Nov 2, 2016

I am trying to apply a function to multiple columns at the same time, and I am struggling to figure out how to do this.

 

Suppose that a Table has "Column 1" and "Column 2" and I want to calculate a quartile of the combined data, essentially I want to stack column 1 on top of column 2, say something like this:

 

q1 = Col Quartile({:Column 1, :Column 2},0.25);

 

This does not work.. but it seems like there is a simple solution...  Any advice or solutions?

 

Thank you in advance!

Brad

1 ACCEPTED SOLUTION

Accepted Solutions
markbailey

Staff

Joined:

Jun 23, 2011

Solution

It sounds like you are using column formulas. This solution should work in a column formula or in a script. I assume that your data table is already open. I opened Big Class to demonstrate the solution. You have to double click the formula so that you can directly type or paste text and then press Enter key.

// assume your data table is already open
// example here is Open( "$SAMPLE_DATA/Big class.jmp" );
Quantile( 0.25, (:height << Get As Matrix) |/ (:weight << Get As Matrix) );

So the Quantile function takes the desired percentile (0.25 for first quartile) as its first argument and a collection of data (list, matrix) as its second argument. It works with any collection of data. (The Col Quantile function is a specialized function that works with a data columnn and retains the result to avoid redundant future computation.) The second argument here is formed by vertically concatenating (symbol is |/ for this operator) the two column vectors obtained from the data columns. The vertical concatenation of the matrices is equivalent to your idea of stacking data columns in the data table. You can extend this concatentaton to any number of columns.

Learn it once, use it forever!
2 REPLIES
markbailey

Staff

Joined:

Jun 23, 2011

Solution

It sounds like you are using column formulas. This solution should work in a column formula or in a script. I assume that your data table is already open. I opened Big Class to demonstrate the solution. You have to double click the formula so that you can directly type or paste text and then press Enter key.

// assume your data table is already open
// example here is Open( "$SAMPLE_DATA/Big class.jmp" );
Quantile( 0.25, (:height << Get As Matrix) |/ (:weight << Get As Matrix) );

So the Quantile function takes the desired percentile (0.25 for first quartile) as its first argument and a collection of data (list, matrix) as its second argument. It works with any collection of data. (The Col Quantile function is a specialized function that works with a data columnn and retains the result to avoid redundant future computation.) The second argument here is formed by vertically concatenating (symbol is |/ for this operator) the two column vectors obtained from the data columns. The vertical concatenation of the matrices is equivalent to your idea of stacking data columns in the data table. You can extend this concatentaton to any number of columns.

Learn it once, use it forever!
drblove

Contributor

Joined:

Nov 2, 2016

That did the trick! Took me a while to catch on to differentiating between between col quartile and quartile functions (doesn't help that the inputs are switched!). Thank you.

Brad