1
It is possible to obtain the desired result with the code below, which groups the results by Name
calculates the maximum value of columns Week
and Weekend
:
df %>%
group_by(Name) %>%
summarise(Week = max(Week, na.rm = TRUE),
Weekend = max(Weekend, na.rm = TRUE))
# A tibble: 2 x 3
Name Week Weekend
<chr> <dbl> <dbl>
1 A 100 2000
2 B 200 1500
The same result would be obtained with virtually any other statistic like min
, median
, mean
etc..
Problems may arise if the data has another format, such as more than one observation NA
by group and column.
Thank you very much Marcus!
– Augusto Schultz