Extract row corresponding to minimum value of a variable by group

前端 未结 6 1821
孤独总比滥情好
孤独总比滥情好 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:41

    Corrected plyr solution:

    ddply(df, .(State), function(x) x[which.min(x$Employees),])
    #   State Company Employees
    # 1    AK       D        24
    # 2    RI       E        19
    

    thanks to @joel.wilson

提交回复
热议问题