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

Formula for calculating averages of values in two consecutive rows

hi

 

 I would like to calculate averages of two consecutive values in separate rows and I have table with 1000 rows.  What formula can I use to do this?

 

Thanks 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Formula for calculating averages of values in two consecutive rows

if(mod(row(),2)==0,
mean(:raw_result,lag(:raw_result)),
.
);

This will calculate the average for every even numbered row and a missing value for each odd numbered row.

Jim

View solution in original post

6 REPLIES 6
jthi
Super User

Re: Formula for calculating averages of values in two consecutive rows

I think Col Moving Average should be able to do it Col Moving Average (jmp.com help) 

 

From scripting index:

jthi_0-1646930018578.png

 

-Jarmo
VR
VR
Level I

Re: Formula for calculating averages of values in two consecutive rows

thanks for the quick response.  I used the formula below:

Col Moving Average( :raw_result, 1, 1, 0 )

 

96     96

93     94.5

100   96.5

110   105

How do i change the formula to get rid of the two underlined values?

 

Thanks again

txnelson
Super User

Re: Formula for calculating averages of values in two consecutive rows

if(mod(row(),2)==0,
mean(:raw_result,lag(:raw_result)),
.
);

This will calculate the average for every even numbered row and a missing value for each odd numbered row.

Jim
VR
VR
Level I

Re: Formula for calculating averages of values in two consecutive rows

Thanks so much, this worked.  

Joseph_Reese
Level IV

Re: Formula for calculating averages of values in two consecutive rows

The previous posted option will work great. You might also consider the Lag() function within the Mean() formula to reference the previous row, so it would read something like the below:

 

Mean( :Column, Lag( :Column ) )

 

 

VR
VR
Level I

Re: Formula for calculating averages of values in two consecutive rows

Thanks, I will try this as well