Help using grpstats function to get number of occurances per row on a table.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Adam Danz
el 29 de Abr. de 2021
My answer uses groupcounts which does not rely on having the stats & machine learning toolbox, unlike grpstats.
Respuestas (1)
Adam Danz
el 28 de Abr. de 2021
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'})
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!