Converting rows to columns
조회 수: 23 (최근 30일)
이전 댓글 표시
I would like to convert Date rows to column and add active numbers for each Date column.
So there will be 14 columns of dates and each coulmn is supposed to keep actives for each country.
I've spent some time trying to sort this out yet there needs to be used so many for loops and manipulation.
Is there any function that i can do it easily ?
This is the code that i used to create the table above.
tbl=table(gs.Country,gs.sum_sum_Active,gs.Date,'VariableNames',{'Country','Active','Date'})
댓글 수: 0
답변 (1개)
Cris LaPierre
2021년 3월 28일
You'll have to be careful. Each column of a table can be a different data type, but all data in a column must be of the same data type. You can make your variables (column names) be dates, but it is likely going to be non-trivial to rearrange your data.
One thought might be to use groupsummary to arrange the data so that each country has the same number of dates.
sumTbl = groupsummary(tbl,["Country","Date"],'mean','IncludeEmptyGroups',true,'IncludeMissingGroups',true)
Ideally each group should have a groupcount of 1, but I specified 'mean' as the way to combine mulitple values.
To do more, I think we would need to see your data to be more specific.
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!