Group Abstract Group Abstract

Message Boards Message Boards

0
|
1.8K Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

How to perform a sort operating on a aggregate operation in a dataset?

I'm having trouble finding the right combination of dataset operations to transform some data into an aggregated form and then sort by the aggregated form.

I think the solution will involve Query, Dataset, GroupBy, and a counting function like CountsBy or Counts or Count. GroupBy didn't work. I have some details in a video.

POSTED BY: Peter Burbery

I made it work with data[GroupBy[#race &]]. I got to the next step with

Query[GroupBy[#race &], CountsBy[#birthplace &]@*Values][data]

Now I just need to sort by the output from the aggregate function. I figured out the sort step with

Query[GroupBy[#race &], Sort@*CountsBy[#birthplace &]@*Values][data]

in descending order and for ascending order I can use

Query[GroupBy[#race &], 
  ReverseSort@*CountsBy[#birthplace &]@*Values][data]

I applied this to some data.

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