cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
WebDesignesCrow
Super User

How to select & colored Top 5 highest value cell from many columns using JSL

Hello Experts,

 

How do I select & colored the Top 5 highest value cell from many columns using JSL?

Example:

From all cells in column Type_A to Type_D (the similarity of these column name is it contains "_")

I want to select & colored the Top 5 highest value cell with yellow.

It seems "Select Where" function only applicable to comparing 2 columns.

 

Expected result should be something like this;

0.14, 0.12,0.11,0.1, 0.9 are the Top 5 highest value cells.

WebDesignesCrow_1-1718770411702.png

 

Thank you.

I'm using JMP 17.2

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to select & colored Top 5 highest value cell from many columns using JSL

Get the column names for all of the columns you are going to seaarch.

Add a new column that contains the Row number

Stack all of the columns you want to search.  Make sure you keep the Row column

Sort the stacked data table in descending order of the Data column

Loop through the first 5 rows of the sorted table and set the cell color in the original table based upon the Label column(column name in original table) and the Row column.

Delete the stacked and sorted data tables

Delete the Row column from the original data table

Jim

View solution in original post

4 REPLIES 4
jthi
Super User

Re: How to select & colored Top 5 highest value cell from many columns using JSL

How do you wish to deal with ties?

-Jarmo
jthi
Super User

Re: How to select & colored Top 5 highest value cell from many columns using JSL

There is an option using matrices (interactive solution suggested by Jim is much easier to understand and was the first idea that come to my mind also)

Names Default To Here(1); 

// This table shows how this will behave with ties
// dt = Open("$SAMPLE_DATA/2D Gaussian Process Example.jmp");
// cols_of_interest = {"X1", "X2"};

dt = Open("$SAMPLE_DATA/Pogo Jumps.jmp");
cols_of_interest = {"Yat", "Yee", "Sam"};

m = dt[0, cols_of_interest];
v = Shape(m, N Items(m));
r = Ranking(v); // let Ranking decide our top5
idx = Loc(r > N Items(m) - 5);

vals = J(1, N Items(m), .);
vals[idx] = 1;
vals = Shape(vals, N Items(m) / N Items(cols_of_interest));

For(i = 1, i <= N Cols(vals), i++,
	rows_to_color = Loc(vals[0, i]);
	Column(dt, cols_of_interest[i]) << Color Cells("Yellow", rows_to_color)
);

Write();

Pogo Jumps.jmp - Yat, Yee, Sam

jthi_0-1718781084937.png

2D Gaussian Process Example.jmp - X1, X2 (note the behavior with ties)

jthi_1-1718781102953.png

 

-Jarmo
txnelson
Super User

Re: How to select & colored Top 5 highest value cell from many columns using JSL

Get the column names for all of the columns you are going to seaarch.

Add a new column that contains the Row number

Stack all of the columns you want to search.  Make sure you keep the Row column

Sort the stacked data table in descending order of the Data column

Loop through the first 5 rows of the sorted table and set the cell color in the original table based upon the Label column(column name in original table) and the Row column.

Delete the stacked and sorted data tables

Delete the Row column from the original data table

Jim
WebDesignesCrow
Super User

Re: How to select & colored Top 5 highest value cell from many columns using JSL

Hi @jthi , 

I thought we have formula like =Top(5, column("Type_A"):column("Type_D) << Color Cell (3);

Where 5 refers to number of Top values from column Type A to column Type D.

I will try @txnelson solution.

 

Thanks !