I have a a dataset with multiple repeated entries, the entries are largely the same, but with data missing, The missing data could be in any field except for the ID. For example:
A tibble: 5 x 4
ID name age fsm
<chr> <chr> <dbl> <dbl>
1 0001 Peter 13 NA
2 0001 NA 13 1
3 0002 Jane 13 1
4 0002 Jane NA 1
5 0003 Billy 12 0
I need to combine the rows, i.e. merging the NAs with the given values from other rows that have the same ID
ID name age fsm
<chr> <chr> <dbl> <dbl>
1 0001 Peter 13 1
2 0002 Jane 13 1
3 0003 Billy 12 0
Above data example as a dput:
structure(list(ID = c("0001", "0001", "0002", "0002", "0003"),
name = c("Peter", NA, "Jane", "Jane", "Billy"), age = c(13,
13, 13, NA, 12), fsm = c(NA, 1, 1, 1, 0)), class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -5L), spec = structure(list(
cols = list(ID = structure(list(), class = c("collector_character",
"collector")), name = structure(list(), class = c("collector_character",
"collector")), age = structure(list(), class = c("collector_double",
"collector")), fsm = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), skip = 1L), class = "col_spec"))