Let's say I have
# A tibble: 4 × 3
Gene.names Case Control
<chr> <dbl> <dbl>
1 A1BG 52 NA
2 A1BG NA 32
3 A2M 16 NA
4 A2M NA 15
As you can see, Gene.names
are duplicates and have corresponding values for Case
and Control
. I need to combine the values for Case
and Control
so they are printed on the same row for each Gene.name
.
I am looking for a solution in dplyr
.
Expected output
Gene.names Case Control
<chr> <dbl> <dbl>
1 A1BG 52 32
2 A2M 16 15
Data
df <- structure(list(Gene.names = c("A1BG", "A1BG", "A2M", "A2M"),
Case = c(52, NA, 16, NA), Control = c(NA, 32, NA, 15)), row.names = c(NA,
-4L), class = c("tbl_df", "tbl", "data.frame"))