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
- :
- Sort a column by variable

Topic Options

- 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

Jun 12, 2017 6:36 AM
(983 views)

Hi,

How would I go about creating a new column that contains the sorted values of one column by another variabe?

An example to hopefully clarify: if I had a table with two rows: Name and age, how would I create a third row that displays the names sorted from oldest to youngest?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

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

Jun 12, 2017 10:12 AM
(1218 views)

Solution

What you've asked for is not easily done in a formula (that I can come up with anyway). It's relatively easy to do this interactively by using **Tables->Sort** to sort the table into a new table and then copy and paste the column of interest back into the original table.

However the question raises some interest about what you're really trying to do.

Generally speaking, a row of a data table represents a collection of values for a single entity – an individual student in your simple example – and each row is unrelated to other rows. I'm not sure how this new column – of Names in your example – would be useful in an analysis since the new column is only meaningful in the context of it's order.

Can you explain a little bit more of how you'd use this new column?

An example to hopefully clarify: if I had a table with two rows: Name and age, how would I create a third row that displays the names sorted from oldest to youngest?

PS: you seem to have confused rows and columns in your example. I'm assuming that you really meant *a table with two columns* and that you wanted to create a third column as your original question states. If I'm mistaken and you really meant rows, please let us know.

-Jeff

3 REPLIES

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

Jun 12, 2017 10:12 AM
(1219 views)

What you've asked for is not easily done in a formula (that I can come up with anyway). It's relatively easy to do this interactively by using **Tables->Sort** to sort the table into a new table and then copy and paste the column of interest back into the original table.

However the question raises some interest about what you're really trying to do.

Generally speaking, a row of a data table represents a collection of values for a single entity – an individual student in your simple example – and each row is unrelated to other rows. I'm not sure how this new column – of Names in your example – would be useful in an analysis since the new column is only meaningful in the context of it's order.

Can you explain a little bit more of how you'd use this new column?

An example to hopefully clarify: if I had a table with two rows: Name and age, how would I create a third row that displays the names sorted from oldest to youngest?

PS: you seem to have confused rows and columns in your example. I'm assuming that you really meant *a table with two columns* and that you wanted to create a third column as your original question states. If I'm mistaken and you really meant rows, please let us know.

-Jeff

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

Oct 31, 2017 7:35 AM
(572 views)

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

Oct 31, 2017 12:36 PM
(556 views)

Give this a try:

```
names default to here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt << New Column(
"Sorted names by age",
Expression,
"None",
Formula( :Name[ Rank( :age << Get Values )][ Row() ] )
);
dt << New Column(
"Sorted names by height",
Expression,
"None",
Formula( :Name[ Rank( :height << Get Values )][ Row() ] )
);
```

Note that it might be slow for large tables.

Edited to show a more relevent example.