Question 1)
I have an R data table with three columns (The actual dataset is bigger but simplifying for better understanding)
Column_One, Column_Two, Column_Three
A, 1, 4
A, 2, 3
A, 3, 77
B, 1, 44
B, 2, 32
B, 3, 770
C, 1, 43
C, 2, 310
C, 3, 68
I want to create a new matrix (data table) from the above as shown below.
A, B, C
4, 44, 43
3, 32, 310
77, 770, 68
Please note in the actual data table there are hundreds of different values for column one and two. Hence a generic solution would be needed.
Any questions, please let me know. Much appreciative of any suggestions.
Question 2)
There could be another level as in a fourth column, column zero, which links a few of the column ones. In this case we need to create new data tables based on column zero and then apply the solution to column one on each sub data table. Please suggest the quickest / simplest way possible.
Column_Zero, Column_One, Column_Two, Column_Three
XX,A, 1, 4
XX,A, 2, 3
XX,A, 3, 77
XX,B, 1, 44
XX,B, 2, 32
XX,B, 3, 770
XX,C, 1, 43
XX,C, 2, 310
XX,C, 3, 68
YY,A1, 1, 4
YY,A1, 2, 3
YY,A1, 3, 77
YY,B1, 1, 44
YY,B1, 2, 32
YY,B1, 3, 770
YY,C1, 1, 43
YY,C1, 2, 310
YY,C1, 3, 68
YY,D2, 1, 4
YY,D2, 2, 5
YY,D2, 3, 6
--------- And so on -----
We then need to create,
------ Data Table one ------
A, B, C
4, 44, 43
3, 32, 310
77, 770, 68
------ Data Table Two ------
A1, B1, C1, D2
4, 44, 43,4
3, 32, 310,5
77, 770, 68,6
------ and so on -----
Related Question:
Once this matrix is split and recast, it becomes important to know the dimensions of the new data structure and its components and also how to access them individually, which is discussed here: