I have table with three columns. The first column contains sample names, the second numbers and the third IDs. Here is an example:
Samples Count ID
S1 99057 Lactobacillales
S1 608 Enterobacterales
S1 507 Choanoflagellida
S1 495 Burkholderiales
S1 456 Pseudomonadales
S1 398 Nostocales
S1 286 Suessiales
S2 3742 Lactobacillales
S2 631 Pseudomonadales
S2 276 Micrococcales
S2 261 Burkholderiales
S2 244 Choanoflagellida
S2 239 Rhizobiales
S2 239 Enterobacterales
I need to transpose and consolidate the table so that the first column contains the IDs, the second the number for each ID in sample S1, and the third the number for each ID in sample S2. Example:
ID S1 S2
Lactobacillales 3742 99057
Enterobacterales 239 608
Choanoflagellida 244 507
Burkholderiales 261 495
Pseudomonadales 631 456
Nostocales 0 398
Suessiales 0 286
Micrococcales 276 0
Rhizobiales 239 0
So far I do it in Excel, but that's not feasible for larger tables. How can this be done in R? Any help greatly appreciated.