Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- Re: Stop a loop

Topic Options

- Start Article
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Oct 13, 2015 7:05 AM
(8122 views)

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 **)**;

**)**;

Solved Go to Solution

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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**)**;

**)**;

3 REPLIES 3

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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**)**;

**)**;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Stop a loop

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Stop a loop