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
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 III

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 III

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,
.
)
)
)