How do I organize a table using a specified cell array?

1 回表示 (過去 30 日間)
Aryan Cross
Aryan Cross 2020 年 11 月 12 日
コメント済み: Star Strider 2020 年 11 月 12 日
In the example found in this documentation, how would I index the data by Gender? Such as if I wanted a new table selecting only rows with {'Male' } or {'Female'}?
I am wondering if it is different than:
rows = (T.Smoker==true & T.Age<40);
T(rows,:)
as it is a cell. Thank you.

採用された回答

Star Strider
Star Strider 2020 年 11 月 12 日
One approach is to use the findgroups function:
load patients
T = table(Age,Gender,Height,Weight,Smoker,...
'RowNames',LastName);
[Grp,ID] = findgroups(T.Gender);
Males = T(Grp==2,:);
The ‘ID’ variable indicates that these are sorted lexiically, so 1=Female, and 2=Male.
  2 件のコメント
Aryan Cross
Aryan Cross 2020 年 11 月 12 日
Thank you!
Star Strider
Star Strider 2020 年 11 月 12 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by