How can one reshape this table?

6 ビュー (過去 30 日間)
alpedhuez
alpedhuez 2021 年 7 月 30 日
編集済み: Matt J 2021 年 7 月 30 日
Consider a table T with
group date visitor
age 18-24 1/1/2021 10
age 18-24 1/2/2021 20
age 25-34 1/1/2021 10
age 25-34 1/2/2021 30
I want to reshape the matrix as
date age18-24 age 25-34
1/1/2021 10 10
1/2/2021 20 30
How can one do this?

採用された回答

Matt J
Matt J 2021 年 7 月 30 日
編集済み: Matt J 2021 年 7 月 30 日
Perhaps as follows?
load tst
T
T = 4×3 table
group date visitor _____________ ____________ _______ {'age 18-24'} {'1/1/2021'} 10 {'age 18-24'} {'1/2/2021'} 20 {'age 25-34'} {'1/1/2021'} 10 {'age 25-34'} {'1/2/2021'} 30
[Gage,IDage]=findgroups(T(:,1));
[Gdate,IDdate]=findgroups(T(:,2));
Tnew=[ IDdate, array2table( accumarray([Gdate,Gage],T{:,3}) , 'Var',IDage{:,1})]
Tnew = 2×3 table
date age 18-24 age 25-34 ____________ _________ _________ {'1/1/2021'} 10 10 {'1/2/2021'} 20 30

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by