It is a toy example.
iris %>% group_by(Species) %>% summarise(max = Sepal.Width[Sepal.Length == max(Sepal.Length)]) # A tibble: 3 x 2 Specie
The which removes the NA elements. If we need to get the same behavior as which where there are NAsuse another condition along with==`
which
NA
use another condition along with
iris %>% group_by(Species) %>% summarise(max = Sepal.Width[Sepal.Length == max(Sepal.Length, na.rm = TRUE) & !is.na(Sepal.Length)])