Extract row corresponding to minimum value of a variable by group

前端 未结 6 1876
孤独总比滥情好
孤独总比滥情好 2020-11-22 04:04

I wish to (1) group data by one variable (State), (2) within each group find the row of minimum value of another variable (Employees), and (3) extr

6条回答
  •  一个人的身影
    2020-11-22 04:42

    Here a dplyr solution ( Note that I am not a regular user ):

    library(dplyr)    
    data %>% 
        group_by(State) %>% 
        slice(which.min(Employees))
    

提交回复
热议问题