Converting rows to columns
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Cris LaPierre
el 28 de Mzo. de 2021
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 comentario
Gorkem Akgul
el 29 de Mzo. de 2021
Editada: Gorkem Akgul
el 29 de Mzo. de 2021
Ver también
Categorías
Más información sobre Linear Algebra en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!