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

Showing results for

- JMP User Community
- :
- Discussions
- :
- How to select every other and third row?

- 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

Jul 8, 2016 11:07 AM
(1525 views)

Hello,

I am a new user, so please excuse me if this seems like an easy question to answer.

I have a data set (21k+ rows) where I want to select the 2nd and 3rd row, unselect the 4th, then select the 5th and 6th, unselect the 7th....so on...

After they are all selected, they can be deleted, as I don't need the data in those rows.

What would be the easiest way to do this?

Thank you very much.

-Matt

1 ACCEPTED SOLUTION

Accepted Solutions

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

Solution

This is a fun question because there are probably lots of strategies for doing this. I'll look forward to seeing other suggestions.

Assuming you want to do this interactively (as opposed to automating with JSL to do it again later) here are a couple ways.

1) Add a new numeric column. Type 1, 2, and 3 in the first three rows of your table. Then select those cells and right click on them and choose **Repeat sequence to end of table.**

This will create a column with a repeating 1, 2, 3. You now need to select the rows with a 2 or a 3 in them. This is easy. Select any "2" cell and any "3" cell (shift-click the second one if you need to or drag select two side by side). Right click on one of the selected cells and choose **Select Matching Cells**.

This will select all of the "2" rows and all of the "3" rows. Now choose **Rows -> Delete Rows**.

2) You could create a Row State column with a formula using the Selected State function to select every 2nd and 3rd row.

Notice that in the Rows to Delete column every 2nd and 3rd row is selected. I did this with the Modulo() function.

Now right click on the star next to the Rows to Delete column and choose **Copy to Row States** to select those rows in the active row state area. Now you can choose **Rows -> Delete Rows**.

I'm sure the Community has other ways to do this. It'll be interesting to see them.

-Jeff

-Jeff

6 REPLIES

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

Jul 8, 2016 11:40 AM
(1270 views)

* Fill -> Repeat Sequence to End of Table*. Finally select both a "2" and a "3", right click to select* Select matching Cells.* Now every other and third row should be selected and ready to be deleted.

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

Jul 8, 2016 11:42 AM
(1270 views)

hi mmcclusk0,

perhaps once basic way of doing this is:

Names Default To Here **(****1)**;

dt = Open**(** "$SAMPLE_DATA/Hurricanes.jmp" **)**;

dt << **new column** **(**"selection", formula **(**sequence **(****1**,**3**,**1** **)))**;

dt:selection << **delete formula**;

// select each second and third row

selectedrows = dt << **select where** **(**:selection >**1** **)**;

dt << **delete rows** **()**;

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

This is a fun question because there are probably lots of strategies for doing this. I'll look forward to seeing other suggestions.

Assuming you want to do this interactively (as opposed to automating with JSL to do it again later) here are a couple ways.

1) Add a new numeric column. Type 1, 2, and 3 in the first three rows of your table. Then select those cells and right click on them and choose **Repeat sequence to end of table.**

This will create a column with a repeating 1, 2, 3. You now need to select the rows with a 2 or a 3 in them. This is easy. Select any "2" cell and any "3" cell (shift-click the second one if you need to or drag select two side by side). Right click on one of the selected cells and choose **Select Matching Cells**.

This will select all of the "2" rows and all of the "3" rows. Now choose **Rows -> Delete Rows**.

2) You could create a Row State column with a formula using the Selected State function to select every 2nd and 3rd row.

Notice that in the Rows to Delete column every 2nd and 3rd row is selected. I did this with the Modulo() function.

Now right click on the star next to the Rows to Delete column and choose **Copy to Row States** to select those rows in the active row state area. Now you can choose **Rows -> Delete Rows**.

I'm sure the Community has other ways to do this. It'll be interesting to see them.

-Jeff

-Jeff

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

Jul 8, 2016 12:43 PM
(1270 views)

Thanks everyone for the quick and easy answers.

I did end up using the added sequence numbers and selecting and deleting as needed.

-Matt

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

Jul 8, 2016 2:08 PM
(1270 views)

Ha! ron_horne beat me to the "select where" strategy. This is one of my favorite things about JMP, though. You can solve problems like this in a way that your mind likes to work. If you are a scripting person, there is a good strategy here, and if you want to do it interactively, jeff.perkinson's ways are good too.

Check out the JMP blog: jmp.com/blog

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

Jul 10, 2016 4:09 PM
(1270 views)

Yet another way to do this. No requirements for adding an extra column or selecting rows:

dt = Current Data Table**()**;

dt << **delete rows****(**dt << **get rows where****(**Mod**(**Row**()** + **2**, **3****)))**;