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?
We can `gather` then `spread`, see example (I changed the input data to demonstrate that this can be used for data with multiple *indiv.IDs*):

    # example data, with 2 IDs
    df1 <- read.table(text = "     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_3703      AA     NA     NA     NA
                      8  Alxis_3703      NA     TT     CC     NA
                      9  Alxis_3703      NA     NA     NA     NA
                      10 Alxis_3703      NA     NA     NA     GG")
    
    
    
    library(dplyr)
    library(tidyr)
    
    gather(df1, key = "k", value = "v", -indiv.ID) %>% 
      filter(!is.na(v)) %>% 
      group_by( indiv.ID) %>% 
      mutate(k = make.unique(k)) %>% 
      spread(key = k, value = v) %>% 
      ungroup()
    
    # # A tibble: 2 x 6
    #   indiv.ID   X86912632 X86912632.1 X86920881 X86922082 X86927699
    #   <fct>      <chr>     <chr>       <chr>     <chr>     <chr>    
    # 1 Alxis_3702 CTGA      TCTG        G         C         NA       
    # 2 Alxis_3703 AA        NA          TT        CC        GG  

