find the column with lowest value in r

一个人想着一个人 提交于 2019-12-07 12:27:39

问题


I have large size matrix and try to find the column that has the minimum value for each row. For instance, here is my matrix, (simply generate with matrix(sample(12),nrow = 3)). With the matrix I want to to have a vector (3,4,1) representing the column number which contains the lowest value in each row. How should I do it? It could be duplicated question but I could not find answers.

      [,1] [,2] [,3] [,4]
[1,]   10   11    1   12
[2,]    8    9    7    3
[3,]    2    5    6    4

回答1:


Use max.col:

max.col(-mat)
# [1] 3 4 1


来源:https://stackoverflow.com/questions/49203020/find-the-column-with-lowest-value-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!