I want to create a matrix in R based on data in a text file. The data in the text file looks like this:
ID1, X, 2
ID1, Y, 1
ID1, Z, 2
ID2, X, 1
ID2, Z, 1
ID3, A, 2
What I would like to do is convert this into a matrix that looks like this:
ID, A, X, Y, Z
ID1, NA, 2, 1, 1
ID2, NA, 1, NA, 1
ID3, 2, NA, NA, NA
I know that if I had this format:
ID1, X
ID1, X
ID1, Y
ID1, Z
ID2, X
ID2, Z
ID3, A
ID3, A
I could use the table command and get what I am looking for but with the solutions I have seen they don't have the data formatting that I have. I can't use these solutions because the data that I'm working with has over 500 million rows in the expanded format if it is not condensed into the format I have above.
How can I create this matrix and what is the most efficient way to do it? Condensed my data is approximately 3 million rows.