Create a new table with filtered rows

I have a table called january_2022. One of the columns, called sports, is categorical. I want to create a new table called sports_basketball which only shows the rows from january_2022 where the value of the sports column is basketball. Any suggestions, please?
Thanks!

回答 (1 件)

the cyclist
the cyclist 2022 年 10 月 16 日

0 投票

Here is one way.
% Pretend data
sports = categorical({'basketball';'volleyball';'basketball'});
num = [2;3;5];
% Put in a table
january_2022 = table(num,sports);
% Pull out the rows you want
sports_basketball = january_2022(ismember(january_2022.sports,'basketball'),:)
sports_basketball = 2×2 table
num sports ___ __________ 2 basketball 5 basketball

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

タグ

質問済み:

2022 年 10 月 16 日

回答済み:

2022 年 10 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by