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
kkrog
Level I

How to set values for last 30 rows of a column?

Hi guys, 

I'm a complete scripting newbie here so please have patience with me .  I have a data set with multiple columns and am trying to make a script that will automatically select the last 30 rows of a column and change the content from "baseline" to "CLCR". Please see my attempt:

 

dt = Current Data Table();
dt1 = dt << Select Columns( :CLCR );
dt1 << select where( Row() > N Rows( dt ) - 30 );
dt1 << set value ("CLCR");

Should I have taken the for loop or while loop approach? 

 

THANKS GUYS ✌

Kristijan Krog
1 REPLY 1
jthi
Super User

Re: How to set values for last 30 rows of a column?

I would use datatable subscripting:

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

dt[N Rows(dt) - 29::N Rows(dt), "height"] = 0;

Edit, one more option:

You can also use get rows where to get specific rows. You can use similar where argument here as you would in select where

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");

// get rows into a matrix
r = dt << Get Rows Where(Row() > N Rows(dt) - 30);

// set values
Column(dt, "height")[r] = 0;

 

-Jarmo