cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
uday_guntupalli
Level VIII

Add Rows Function Question

All, 

        I am using JMP 13.1.0 on a Windows 7 machine. 

        I am trying to add rows to a data table after a specific row. 

       According to the documentation (http://www.jmp.com/support/help/13-2/Add_Rows_2.shtml)  that I am referencing, the correct way to do that is : 

  

dt << Add Rows( 3, 10 ); /* add 3 rows after the 10th row, moving the 11th and lower rows farther down */

        Now , I expand on that to do this : 

 

dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" ); // Open Sample Data 

RowStyle1 = {:name = "Mark",:age = 12,:sex = "M",:height = 80,:weight = 102}; // Define Row To Add 

RowIndex = 1 ; // Define position to add desired row 

dt1 << Add Rows(RowStyle1,RowIndex); // Add Rows . 

The result of this piece of code is shown in the screeshot below : 

 

image.png

Shouldn't the row be added after row 1 - essentially moving rows 2 through 40 down ? 
Can someone point out what i am doing wrong here? 

 

Also - would like to add one more question on Add Rows() : 

RowStyle2 = {:name = "Mark",:age = 12,:sex = "M",:height = 80,:weight = :weight[1]/2}; // Define Row To Add 

If instead of a pre-defined value, I wanted to use a dynamic value like shown above RowStyle2 vs RowStyle1 - should I be using expressions? If yes - please provide an example. 

Best
Uday
2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: Add Rows Function Question

I do not know if it is the best way, but it works:

Open( "$SAMPLE_DATA/Big Class.jmp" ); // Open Sample Data
RowStyle1 = {:name = "Mark",:age = 12,:sex = "M",:height = 80,:weight = 102}; // Define Row To Add
RowIndex = 10 ; // Define position to add desired row  
dt1 << add Rows(RowStyle1 );
dt1 << Select Rows(n rows(dt1));
dt1 << Move Rows(After(RowIndex)); // Add Rows .

 

 

View solution in original post

Re: Add Rows Function Question

In addition to what @vladbondarenko0 already provided, you can use JMP 13 data table subscripting to set all the row values at once after you already added the row where you want.

dt << Add Rows(1,1);
dt[[2],{name,age,sex,height,weight}] = {{"Mark", 14, "M", 61, 124}};

Looking at the documentation, specifying a row position in the Add Rows message is not supported when using the list of values approach. The row index position is only used when inserting n empty rows. Feel free to shoot us an email at support@jmp.com and we can add this as a feature request for consideration in a future release of JMP.

Justin

View solution in original post

8 REPLIES 8

Re: Add Rows Function Question

I do not know if it is the best way, but it works:

Open( "$SAMPLE_DATA/Big Class.jmp" ); // Open Sample Data
RowStyle1 = {:name = "Mark",:age = 12,:sex = "M",:height = 80,:weight = 102}; // Define Row To Add
RowIndex = 10 ; // Define position to add desired row  
dt1 << add Rows(RowStyle1 );
dt1 << Select Rows(n rows(dt1));
dt1 << Move Rows(After(RowIndex)); // Add Rows .

 

 

uday_guntupalli
Level VIII

Re: Add Rows Function Question

Appreciate the idea @vladbindarenko0 but I want to understand why the documented method is not working
Best
Uday
txnelson
Super User

Re: Add Rows Function Question

@uday_guntupalli

The documented code works correctly.  I think what you are missing, is that the Add Rows() function has 2 different code structures, and that mixing the 2 structures does not work.

Add Rows(1) or Add Rows(1,3) is one of the syntax structures

and

Add Rows({list}) or Add Rows({List of Lists}) is the second structure

 

My testing of the code does not permit the mixing of the 2 syntax structures

Jim

Re: Add Rows Function Question

In addition to what @vladbondarenko0 already provided, you can use JMP 13 data table subscripting to set all the row values at once after you already added the row where you want.

dt << Add Rows(1,1);
dt[[2],{name,age,sex,height,weight}] = {{"Mark", 14, "M", 61, 124}};

Looking at the documentation, specifying a row position in the Add Rows message is not supported when using the list of values approach. The row index position is only used when inserting n empty rows. Feel free to shoot us an email at support@jmp.com and we can add this as a feature request for consideration in a future release of JMP.

Justin
Byron_JMP
Staff

Re: Add Rows Function Question

@Justin_Chilton  Nice Tip!  I'm going to keep that one in my tool box.

Thanks,

-B

JMP Systems Engineer, Health and Life Sciences (Pharma)

Re: Add Rows Function Question

@Byron_JMP, you might want to check out @Craige_Hales' blog Data table subscripting for more cool examples like that.

Justin
HauNguyen
Level I

Re: Add Rows Function Question

Hi All.

i have a table like this:

 

Module    MONTH     COST

STHI           1             15

STHI           2             20

STHI           3             25

STHI           5             30

OLB           1              44

OLB           2             54

OLB           4              33

OLB          5               22

 

as you can see, month colluum is missing some months in a row. and i also want to cumulative sum the cost coluum base on module into a new coluum, the new table will be like this:

 

Module    Month    cost      totalcost

STHI         1           15           15

STHI         2           20           35

STHI         3           25           60

STHI         4           0             60

STHI        5            30           90

OLB         1            44          44

OLB         2            54          98

OLB         3             0           98

OLB         4             33        131

OLB         5            22         153

 

is there any way to transfer to the table like this, could you please to help me. Thank you so much

txnelson
Super User

Re: Add Rows Function Question

create a new column and give it the formula

col cumulative sum( :Cost )
Jim