cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Use World Cup data to build models, explore spatial relationships, and create informative visualizations in JMP. Register. July 17, 2 pm US Eastern Time.
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

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

How to directly calculate the number of consecutive conditions?

For example, take "height" as an example and count the consecutive number of "height"s in the row greater than the "height" in the previous row.

 

I added an auxiliary column h to determine whether the "height" of the row is greater than the "height" of the previous row, and then counted the consecutive "height" of the row greater than the "height" of the previous row in the other column.If the "height" is less than the "height" of the previous row  have to recalculate.

2019-11-18_20-23.png

 

  • How can do this calculation in one step?

  • I tried this, but it didn't work:

  • if(:height>Lag(:height,1),row()-Contains(:height[Index(1,Row())],:height<Lag(:height,1),-1))
  • Thanks!
12 REPLIES 12
johnmoore
Level IV

Re: How to directly calculate the number of consecutive conditions?

Looks like second If had a single = for assignment instead of a == for equivalence test.  

If( Row() == 1,
    hCounter = 0,
    If(
        Lag( :name ) == :name,
            If( :age > Lag( :age, 1 ),
                Empty()
            ),
        hCounter++, hCounter = 0
    )
);
If( hCounter == 0,
    .,
    hCounter
);

  

Onjai
Level IV

Re: How to directly calculate the number of consecutive conditions?

Hi John,

I see the error but this does not provide the calculation and checks I require.  My last post shows a new data table and formula that is close.

Thank you

Onjai

Onjai
Level IV

Re: How to directly calculate the number of consecutive conditions?

Hi everyone,

It took me awhile but I eventually figured out how to add a value to the previous row if the condition was true. 

So I want to share this with you.  I am using this to tag sequential values within groups.

Thank you all.

Cheers!

 

If( Row() == 1,
.,
If( :master == Lag( :master ),
If( :roll - Lag( :roll ) == 1,
:seq. rolls v3[Row() - 1] = 1,
.
)
)
)

Recommended Articles