I want to collapse duplicated rows, by unique record ID, in order to consolidate unique variables that exist on these duplicated rows. Certain variables are only listed on one version of the duplicate row, while other variables that are unique exist on a different row of the duplicated record. I'm working in R. I'd like to just have records exist on one row, without losing any of the unique columns. One "sum-total" row basically, that collects each of the columns that may have been filled on different rows, so that this final row is not a duplicate, and shows each variable that could have been filled all together...
I've looked into merge and bind, and I've thought about writing an If rule, but the duplication vary by record (see example)..
record Var1 var2 var3 var4 var5
2 1 1 NA NA NA
2 NA NA 1 1 1
3 2 2 NA NA NA
3 NA NA 2 NA NA
3 NA NA NA 2 2
4 1 1 NA NA NA
5 NA NA 1 1 1
5 NA 2 NA NA NA
desired output example of record 2:
record Var1 var2 var3 var4 var5
2 1 1 1 1 1
3 ....