Find and compare rows in table by column value

4 ビュー (過去 30 日間)
Maximilian Myllyaho Forsberg
Maximilian Myllyaho Forsberg 2022 年 1 月 5 日
回答済み: dpb 2022 年 1 月 5 日
Hello i have a table in witch I only care about two columns. The table looks something like this
Year_Birth | Income | Martial status | ... | ... | ... | Ed_level |
1992 | 2000 | Divorced | ... | ... | ... | High |
1989 | 6700 | Divorced | ... | ... | ... | low |
1994 | 8900 | Divorced | ... | ... | ... | High |
..... | ..... | ...... | ... | ... | ... | .... |
I want to be able to look at "Ed_Level" and take 50 random rows with "High" Ed_level and take the mean of their income (Get their mean etc).
So far I have been able to take out the groups and get their mean by doing the following:
G = findgroups(table.Ed_level);
meanInc = splitapply(@mean, table.Income, G);
But i cant seem to figure out how to get out 50 random sambles of only one of the diffrent "Ed_levels".

回答 (1 件)

dpb
dpb 2022 年 1 月 5 日
groupsummary(table,{'Year','Ed_level'},@(x)mean(x(randperm(numel(x),50)),'Income')

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by