library(dplyr)
df %>%
group_by(Date)%>%
summarise_at(.,c("A","B","C"),function(x) if(any(!is.na(x)))sum(x,na.rm = T) else NA)
# A tibble: 3 x 4
Date A B C
<fct> <int> <int> <int>
1 2015-01-17 1 NA 1
2 2015-01-18 NA NA NA
3 2015-01-19 2 2 4
данные:
df <- structure(list(Date = structure(c(1L, 2L, 3L, 3L), .Label = c("2015-01-17",
"2015-01-18", "2015-01-19"), class = "factor"), A = c(1L, NA,
1L, 1L), B = c(NA, NA, 2L, NA), C = c(1L, NA, 3L, 1L)), class = "data.frame", row.names = c("1",
"2", "3", "4"))