Rearranging tables based on elements

1 view (last 30 days)
atom51
atom51 on 17 Mar 2022
Answered: Scott MacKenzie on 17 Mar 2022
I have a dataset with for 4 students with their grades over 6 months generated as follows:
month ranks grades
1 2 3 4 1 2 3 4
---------- ---------- ----------- -------- ------ ------ ------- --------
1 st_A st_B st_C st_D 98 95 87 80
2 st_A st_B st_C st_D 100 93 89 81
3 st_A st_C st_B st_D 99 95 90 80
4 st_C st_A st_B st_D 100 99 95 70
5 st_A st_C st_D st_B 98 95 90 80
6 st_A st_C st_B st_D 94 90 88 84
is there a simple way to rearrange the table such that instead of having the ranks as headers, the students become the headers and their grades are mapped accordingly ?? so that the output is as follows
month students
st_A st_B st_C st_D
---------- ---------- ----------- --------
1 98 95 87 80
2 100 93 89 81
3 99 90 95 80
4 99 95 100 70
5 98 80 95 90
6 94 88 90 84

Answers (1)

Scott MacKenzie
Scott MacKenzie on 17 Mar 2022
For tables, an effective way to "transpose" (switch rows with columns, including variable names) is using the rows2vars function. You need to be working with R2018a or later, however. There are examples in the documentation.

Categories

Find more on Tables in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!