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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by