フィルターのクリア

Count occurrences of categorical conjunction

2 ビュー (過去 30 日間)
Nex
Nex 2021 年 9 月 28 日
回答済み: Chunru 2021 年 9 月 28 日
Given two separate categorical variables with the same length (refering to the same data):
Cat_one = categorical({'A'; 'B'; 'A'; 'D'; 'C'; 'B'; 'B'; 'A'; 'A'});
Cat_two = categorical({'X'; 'X'; 'Y'; 'Y'; 'Y'; 'X'; 'Y'; 'X'; 'X'});
How can I find the average occurences of each unique item in Cat_one within group X of Cat_two?

採用された回答

Chunru
Chunru 2021 年 9 月 28 日
Cat_one = categorical({'A'; 'B'; 'A'; 'D'; 'C'; 'B'; 'B'; 'A'; 'A'});
Cat_two = categorical({'X'; 'X'; 'Y'; 'Y'; 'Y'; 'X'; 'Y'; 'X'; 'X'});
u1 = unique(Cat_one);
for i=1:length(u1)
idx = Cat_one == u1(i);
c(i) = sum(Cat_two(idx) == 'X');
end
c % corresponding occurence of 'X'; Not sure the definition of averaging
c = 1×4
3 2 0 0

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by