Aggregate by factor levels, keeping other variables in the resulting data frame

前端 未结 5 2077
太阳男子
太阳男子 2020-12-05 18:45

I\'m trying to calculate the minimum values of a numeric column for each level of a factor, while keeping values of another factor in the resulting data frame.



        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 19:32

    Well, a few minutes more searching would have gotten me there... this answer seems to do the trick:

    merge(dat, aggregate(value ~ code, dat, min))

提交回复
热议问题