How do you get multiple minimum values in a column based on grouping and then isolate the corresponding rows for the whole table?
Show older comments
I've got a list of ages in a table, sorted, and grouped by 'names'. Something like this:
perName=findgroups(data.names);
b = splitapply(@(x1){sort(x1)}, data.age, perName);
How do I select the youngest 10 ages (smallest) for every name group (or largest for that matter)? Do I need to build a custom function then reference that function in the splitapply command?
Normally, I can sort the column and just trim out (or isolate) the top several using something like this (for example):
data(1:15,:) = [];
However, I've spent a long time without any luck to trim/isolate based on grouping. It was easy to get the min value using @min funciton, but I'm not sure how to get 'multiple' min or max values for each group
Also, once I've managed to find the top ten, how do I also isolate the corresponding rows in the table for different columns?
Any help is much appreciated!
(edit: I've attached the matlab table for reference. Note this is just made up 'dummy' data for practice. Once I figure it out I have to apply to a much larger dataset.)
2 Comments
Image Analyst
on 28 Jul 2020
You forgot to attach your data so I don't think anybody is going to try anything until that happens.
Joshua Murray
on 28 Jul 2020
Accepted Answer
More Answers (0)
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!