How do I count changes in row values?I have a large data set where I have blocks of repeating values like this:
A
A
B
A
C
C
C
I would like to count the number of changes in row values or, in other words, a count of rows ignoring consecutive repeated rows. In this example, the count would be 4 (The third 'A' is a change from 'B', so it counts). Is there a way to have JMP count rows ignoring repeated and consecutive duplicates?
I'm using JMP 15.2.1.
Data TableRe: How do I count changes in row values?It seems to be working! Thanks!
Re: How do I count changes in row values?One way would be to create formula using Lag and then you can get max value of that column
If(
Row() == 1,
counter = 1;
, Lag(:col, 1) != :col,
counter++
);
counter;
</CODE><SPAN class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1647639220121.png" style="width: 400px;"><SPAN class="lia-inline-image-display-wrapper" image-alt="jthi_0-1647639220121.png" style="width: 207px;"><span class="lia-inline-image-display-wrapper" image-alt="jthi_0-1647639220121.png" style="width: 207px;"><img src="https://us.v-cdn.net/6038925/uploads/images/40960i3683E856360E0C73/jthi_0-1647639220121.png" role="button" title="jthi_0-1647639220121.png" alt="jthi_0-1647639220121.png" /></span></SPAN></SPAN></P>
<P> </P>
<P> </P>
<P>Maybe something like this could also work:</P>
<P> </P>
<PRE><CODE class=" language-jsl">Col Cumulative Sum(Lag(:col) != :col)
Re: How do I count changes in row values?Here are a couple of ways to handle this

Names Default To Here( 1 );
dt = Current Data Table();
For Each Row(
If(
Row() == 1, count = 1,
:column 1 != Lag( :column 1 ), count
++)
);
Show( count );
// Look in the log for the value of count
// or
dt << New Column( "The Count",
formula(
If(
Row() == 1, count = 1,
:column 1 != Lag( :column 1 ), count
++);
count;
)
);