Extracting indices for data frame rows that have MAX value for named field

后端 未结 3 1258
迷失自我
迷失自我 2020-12-06 02:23

I have a data frame that is rather large and I need a good way (explained bellow) to extract indices for rows that have maximum values for a given field, within a certain se

3条回答
  •  孤街浪徒
    2020-12-06 03:14

    Perhaps this may help:

    tapply(seq(dim(d)[1]), d$label, function(rns){rns[which.max(d$value[rns])]} )
    

    (note: I got this trick from the code of 'by')

提交回复
热议问题