cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

Solve problems, and share tips and tricks with other JMP users.
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 :crossed_fingers:.  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

Recommended Articles