I have a data.frame where I need to collapse rows by sample names in the indiv.ID column. Here is an excerpt:
indiv.ID 86912632 86920881 86922082 86927699
1 Alxis_3702 CTGA <NA> <NA> <NA>
2 Alxis_3702 TCTG <NA> <NA> <NA>
3 Alxis_3702 <NA> G <NA> <NA>
4 Alxis_3702 <NA> <NA> C <NA>
5 Alxis_3702 <NA> <NA> <NA> <NA>
6 Alxis_3702 <NA> <NA> <NA> <NA>
7 Alxis_3702 <NA> <NA> <NA> <NA>
8 Alxis_3702 <NA> <NA> <NA> <NA>
9 Alxis_3702 <NA> <NA> <NA> <NA>
10 Alxis_3702 <NA> <NA> <NA> <NA>
In theory it should be easy to merge all rows with the same indiv.ID, but in the case of rows 1 and 2, I also need a new column (because this locus is heterozygous), so that each row only has one individual, like so:
indiv.ID 86912632 86912632.1 86920881 86922082 86927699
Alxis_3702 CTGA TCTG G C <NA>
What is the best way to do this?