<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Hi All,
I have a log file of temperature at unequal intervals and the duration between them.
I want to clean the dataset so there will be no repeating temperatures and no short intervals between the same temperature measurements.
To delete the repetitions I use the following code:
Repeats = dt << get rows where( Lag( :Temperature, 1 ) == :Temperature );
dt << delete rows( repeats );
For the short jumps between same temperatures I use:
Jumps = dt << get rows where( And( Lag( :Temperature, 1 ) == Lag( :Temperature, -1 ), :Duration < 2 ) );
dt << delete rows( Jumps );
this is done repetitively since once the Jumps are cleaned there could be new Repeats and the other way round. So I use it in a for loop. I can always do this excessively (setting i to a high number) but it is inefficient.
Any suggestions to improve the loop so it stops when there are no repeats of Jumps?
The overall script looks like this:
dt = New Table( "Log File", Add Rows( 500 ) );
dt << New Column( "Temperature",
Set Property( "Value Colors", {1 = -13977687, 2 = -3780931, 3 = -4222943, 4 = -13596966, 5 = -2211217} ),
Color Cell by Value
);
For Each Row( dt:Temperature = Random Integer( 5 ) );
dt << New Column( "Duration" );
For Each Row( dt:Duration = Random Integer( 3 ) );
// delete repeating rows and short jumps
For( i = 1, i <= 5, i++,
Repeats = dt << get rows where( Lag( :Temperature, 1 ) == :Temperature );
dt << delete rows( repeats );
Jumps = dt << get rows where( And( Lag( :Temperature, 1 ) == Lag( :Temperature, -1 ), :Duration < 2 ) );
dt << delete rows( Jumps );
);
Yes, they are equivalent. The sum always returns a number and JMP treats all non-zero numbers as TRUE. So it does not matter if the test returns 1 or 37. Both are equally TRUE.
Thaks @ms,
could you explain how jmp reads N Row(Repeats)+N Row(Jumps) as a test expression?
Is it equivalent to:
Or (N Row(Repeats) , N Row(Jumps)) > 0
ron
You could try a while loop. The below loop should stop when both Repeat and Jumps are empty matrices.
Jumps = Repeats = [1];
While(N Row(Repeats) + N Row(Jumps),
Repeats = dt << get rows where(Lag(:Temperature, 1) == :Temperature);
dt << delete rows(repeats);
Jumps = dt << get rows where(And(Lag(:Temperature, 1) == Lag(:Temperature, -1), :Duration < 2));
dt << delete rows(Jumps);
);