How do you get multiple minimum values in a column based on grouping and then isolate the corresponding rows for the whole table?
이전 댓글 표시
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
Image Analyst
2020년 7월 28일
You forgot to attach your data so I don't think anybody is going to try anything until that happens.
Joshua Murray
2020년 7월 28일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!