This should probably be easy, but I'm unable to find the answer on my own.
Take for example the iris dataset, I want to get the max petal width for each species, using this query:
iris %>% group_by(Species) %>% summarise(max(Petal.Width))
Which returns the following result:
# A tibble: 3 x 2
Species `max(Petal.Width)`
<fct> <dbl>
1 setosa 0.6
2 versicolor 1.8
3 virginica 2.5
Now I want to know the petal length of each of those rows with max petal width values.[1] How would I go about doing this? A select is not working:
iris %>% group_by(Species) %>% select(Species,Petal.Length,Petal.Width) %>% summarise(max_val = max(Petal.Width))
Because I don't get the petal length attribute is still missing with this.
1: For example, the row where the petal width is 1.8 and the species is versicolor, the petal length is 4.8 - and I would like to have this info with the result.