(Using Iris for reproducibility)

I want to calculate min/max row by Petal.Width & grouped by Species in R. I have done that using two approaches, I want to understand is there a better approach (preferably tidyverse) , also note because of ties answer might vary in both. Please correct if there is anything wrong in both these approaches.

**Approach 1**

```
library(tidyverse)

iris %>% 
 group_by(Species) %>% 
  slice_max(Petal.Width, n = 1, with_ties=FALSE) %>% 
  rbind(
iris %>% 
 group_by(Species) %>% 
  slice_min(Petal.Width, n = 1, with_ties=FALSE)) 

```

**Approach 2**

```
iris %>% 
  group_by(Species) %>% 
  arrange(Petal.Width) %>% 
  filter(row_number() %in% c(1,n()))

```