cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Image to Table JMP extension imports single or batch images as data tables. Useful to extract curves from pictures or convert image data to curve data to use in analyses like Functional Data Explorer. Download and install the extension.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Alicia
Level III

Calculate difference between values in consecutive rows by group

Hi There,

 

I have a data table with 2 columns like the below:

group value
1     10
1     20
1     25
2     5
2     10
2     15 

I want to create a new column, "diff", that calculates the differences between consecutive rows, grouped by "group", so I would have something like this:

 

group value diff
1     10    . # because there is a no previous value
1     20    10 # value[2] - value[1]
1     25    5  # value[3] value[2]
2     5     . # because group is changed
2     10    5  # value[5] - value[4]
2     15    5  # value[6] - value[5]

Please can you help me with the jsl for the column formula?

 

Many thanks,

 

Alicia

 

1 ACCEPTED SOLUTION

Accepted Solutions
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Calculate difference between values in consecutive rows by group

If the table is always sorted by group like your example you could do this with an if statement:

 

If( Lag( :group ) == :group,
	:value - Lag( :value ),
	.
)

View solution in original post

2 REPLIES 2
ih
Super User (Alumni) ih
Super User (Alumni)

Re: Calculate difference between values in consecutive rows by group

If the table is always sorted by group like your example you could do this with an if statement:

 

If( Lag( :group ) == :group,
	:value - Lag( :value ),
	.
)
Alicia
Level III

Re: Calculate difference between values in consecutive rows by group

Works perfectly! Thanks so much

Recommended Articles