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
- :
- To find the increase or decrease of values in each row in the same column

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

Highlighted

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

Feb 19, 2019 1:02 AM
(1820 views)

Hi,

The objective that I want to achieve in this task is if the values change from "1 to 2" or "2 to 1" for 2 consecutive days in the Sigma column, then remove that two rows. Can It be done?

Please refer attached my data set.

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions

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

There are several ways to do this. Here's one example using JSL. It selects both rows that match the criteria. Un-comment the last line of code to delete the rows. Note that as rows are deleted new row pairs with "1 to 2" or "2 to 1" may be created, but the days will not be consecutive.

```
//Example Table
dt = New Table("untitled 28994",
Add Rows(39),
New Column("Day", Numeric, "Continuous", Format("Best", 12), Set Values(1 :: 39)),
New Column("Sigma", Numeric, "Continuous", Set values(J(39, 1, Random Integer(0, 2))))
);
// Locate row sequence pairs which product = 2
n = N Row(dt);
m = Loc(:Sigma[1 :: n - 1] :* :Sigma[2 :: n] == 2);
dt << select rows(m |/ m + 1);
// dt << delete rows;
```

4 REPLIES 4

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

Re: To find the increase or decrease of values in each row in the same column

Of course it can be done....however, your description is a bit confusing to me. Could you please elaborate by indicating on your attached example, which of the Days would be removed?

Jim

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

Re: To find the increase or decrease of values in each row in the same column

For example, in day 5 and 6, the sigma value has change from 1 to 2. Hence, to remove the rows in day 5 and 6. So it will keep checking for the rest of the rows and delete it if there are changes from 1 to 2 or 2 to 1.

Thank you.

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

There are several ways to do this. Here's one example using JSL. It selects both rows that match the criteria. Un-comment the last line of code to delete the rows. Note that as rows are deleted new row pairs with "1 to 2" or "2 to 1" may be created, but the days will not be consecutive.

```
//Example Table
dt = New Table("untitled 28994",
Add Rows(39),
New Column("Day", Numeric, "Continuous", Format("Best", 12), Set Values(1 :: 39)),
New Column("Sigma", Numeric, "Continuous", Set values(J(39, 1, Random Integer(0, 2))))
);
// Locate row sequence pairs which product = 2
n = N Row(dt);
m = Loc(:Sigma[1 :: n - 1] :* :Sigma[2 :: n] == 2);
dt << select rows(m |/ m + 1);
// dt << delete rows;
```

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

Re: To find the increase or decrease of values in each row in the same column

Hi,

Thank you for the solution below. However, I noticed that it has removed day 11 which the sigma is "0 to 2". But I only want to remove rows with sigma " 1 to 2" or "2 to 1" only. Please advise.

Thank you.