Message Boards Message Boards

1
|
8798 Views
|
3 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Dataset - Sort in Highest to Lowest Order

Posted 10 years ago

Hi all,

Where dataset is a Dataset with plenty of rows and several attributes, and AttributeName is exactly that, this...

dataset[SortBy["AttributeName"]]

...sorts my dataset entries in lowest to highest order by AttributeName.

I cannot seem to find any way to sort in the reverse order.

Thanks in advance

Brad

POSTED BY: Brad Varey
3 Replies

You can then Reverse all set:

planets = ExampleData[{"Dataset", "Planets"}];
planets[SortBy["Mass"], "Mass"][Reverse]

enter image description here

POSTED BY: Vitaliy Kaurov
Posted 10 years ago

Thanks, Vitaliy

I will admit I had considered this, but assumed there must be a more efficient way other than sorting then reversing.

But now I wonder if I misunderstand the syntax: does the [Reverse] keyword simply cause the initial sort to be in reverse order, or does the process actually involve first sorting, then reversing?

Likewise, perhaps I misunderstand the magic that is Dataset -- perhaps Reverse is a much more efficient operation than it sounds.

POSTED BY: Brad Varey

Depends on the order of operations, non-commutator operations in general:

titanic = ExampleData[{"Dataset", "Titanic"}];

In[22]:= (titanic[SortBy["age"]] // Normal) == (titanic[Reverse][SortBy["age"]] // Normal)    
Out[22]= True

In[23]:= (titanic[SortBy["age"]][Reverse] // Normal) == (titanic[Reverse][SortBy["age"]] // Normal)    
Out[23]= False
POSTED BY: Vitaliy Kaurov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract