Per-group totals with tapply(x, g, sum, na.rm = TRUE), and one group came back as 0. Every value in that group is NA. Not a single measurement, and the table says the total was zero.
x <- c(NA_real_, NA_real_)
sum(x, na.rm = TRUE)
#> [1] 0
mean(x, na.rm = TRUE)
#> [1] NaN
max(x, na.rm = TRUE)
#> [1] -Inf
# plus a warning about no non-missing arguments
Each answer is defensible on its own. An empty sum is 0 and an empty mean is 0/0. Side by side in a summary table they are three different ways of saying nothing was there, and only max bothers to mention it. The 0 is the worst of them because it looks like a measurement.
The version that goes into my scripts from now on returns NA when there was nothing to add.
sum_or_na <- function(x) {
if (all(is.na(x))) NA_real_ else sum(x, na.rm = TRUE)
}
I prefer the NA, since a reader of the table can at least see that the group had no data.