Converting rows to columns
21 ビュー (過去 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.
1 件のコメント
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!