Group Abstract Group Abstract

Message Boards Message Boards

1
|
4.7K Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:
GROUPS:

[?] Use operator form of MaximalBy[] also specifying the number of items?

Posted 6 years ago

I would like to write a Query[] to pick out say the top three items from a dataset.

I start with this

mydata[MaximalBy[#Value &]]

which gives me the data row with the largest "value". To get the top 3 I would need an operator form of MaximalBy that allows me to specify the number of items (e.g. 3), but according to the documentation this is not available. Is there an elegant workaround or do I need to do this?

mydata[SortBy[#Value &] /* Reverse /* Part[1 ;; 3]]

Many thanks

POSTED BY: Andrew Read
2 Replies
Posted 6 years ago

It works. Thank you Sander

POSTED BY: Andrew Read

Using a pure (or anonymous or lambda) function:

MaximalBy[#, #Value &, 3] &

should work.

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard