Help using grpstats function to get number of occurances per row on a table.

2 ビュー (過去 30 日間)
Ajpaezm
Ajpaezm 2021 年 4 月 28 日
コメント済み: Adam Danz 2021 年 4 月 29 日
I have the following table (4 rows, column names are simply "Col1", "Col2" and so on), for which I'd like to apply grpstats function on.
'China','Hong Kong', '', 'China'
'', 'Switzerland', '', 'Switzerland'
'United States', 'Ireland', '', 'United States'
'Finland', 'Finland', 'Sweden', ''
What I would like to do is to get is the most repeated observation across the rows, using such function without needing to use a combination of accumaray, categorical and unique.
How may I use it? Can you help please?
  3 件のコメント
Ajpaezm
Ajpaezm 2021 年 4 月 28 日
Hello Adam, thanks for your input.
Let me rephrase the question a bit: What I intend to do with grpstats is to make a count of the occurances across the rows of my array first (this is where I think grpstats can be useful). Later on is just on me to check or select the highest number of occurances.
I've edited my question to avoid confusion.
Adam Danz
Adam Danz 2021 年 4 月 29 日
My answer uses groupcounts which does not rely on having the stats & machine learning toolbox, unlike grpstats.

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

回答 (1 件)

Adam Danz
Adam Danz 2021 年 4 月 28 日
C = {'China','Hong Kong', '', 'China'
'', 'Switzerland', '', 'Switzerland'
'United States', 'Ireland', '', 'United States'
'Finland', 'Finland', 'Sweden', ''};
rowNum = repmat((1:size(C,1))', 1, size(C,2));
T = table(C(:),rowNum(:),'VariableNames',{'Country','RowNum'});
B = groupcounts(T,{'RowNum','Country'})
B = 11×4 table
RowNum Country GroupCount Percent ______ _________________ __________ _______ 1 {0×0 char } 1 6.25 1 {'China' } 2 12.5 1 {'Hong Kong' } 1 6.25 2 {0×0 char } 2 12.5 2 {'Switzerland' } 2 12.5 3 {0×0 char } 1 6.25 3 {'Ireland' } 1 6.25 3 {'United States'} 2 12.5 4 {0×0 char } 1 6.25 4 {'Finland' } 2 12.5 4 {'Sweden' } 1 6.25

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by