I have the following data frame,
id <- c(10, 12, 13, 14, 15)
x.a <- c(1, 1, 0, 0, 1)
x.b <- c(NA, NA, NA, 5, 4)
y.a <- c(0,0,0, NA, NA)
y.b <- c(0, 0, 1, 1, NA)
df <- data.frame(id, x.a, x.b, y.a, y.b)
df
> df
id x.a x.b y.a y.b
1 10 1 NA 0 0
2 12 1 NA 0 0
3 13 0 NA 0 1
4 14 0 5 NA 1
5 15 1 4 NA NA
I want to summarise across columns (e.g. min, max). This is what I am doing,
df %>%
group_by(id) %>%
summarise(across(ends_with("a"), (x) max(x, na.rm = TRUE))) %>%
summarise(across(ends_with("b"), (x) min(x, na.rm = TRUE)))
This is giving me an error message like this,
Warning message:
There were 2 warnings in `summarise()`.
The first warning was:
ℹ In argument: `across(ends_with("a"), max, na.rm = TRUE)`.
ℹ In group 4: `id = 14`.
Caused by warning in `fn()`:
! no non-missing arguments to max; returning -Inf
ℹ Run dplyr::last_dplyr_warnings() to see the 1 remaining warning.
Any idea what am I doing wrong here?