R: finding column with minimum value in each row when there is a tied

后端 未结 3 1335
误落风尘
误落风尘 2021-01-19 21:51

Here is my data example:

>dat <- matrix(c(59,50,48,44,44,NA,78,59,42,67,51,NA,72,64,64),byrow=TRUE,ncol=3) 
>k <- apply(dat, 1, function(x) whic         


        
3条回答
  •  无人共我
    2021-01-19 22:00

    do you want a maximum index for each row?
    then,

    > k <- apply(dat, 1, function(x) max(which(x == min(x, na.rm = TRUE))))
    > k
    [1] 3 2 3 2 3
    

    will do that.

提交回复
热议问题