Vote count: 0
How can I create a subset by the highest value of a certain variable in a data frame?
I have the following dataframe, from which I want to extract the highest value of V1 by name:
name V1 V2
1 name1 1 f
2 name1 2 b
3 name1 5 c
4 name2 3 f
5 name2 8 g
6 name2 2 m
The subset should look like this
name V1 V2
3 name1 5 c
5 name2 8 g
asked 47 secs ago
1 Answer
Vote count: 0
We can use dplyr
library(dplyr)
df1 %>% group_by(name) %>% slice(which.max(V1))
answered just now
Subset by highest value of a variable (R)
Aucun commentaire:
Enregistrer un commentaire