本文介绍了在r中找到具有最低值的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个大尺寸的矩阵,并尝试查找每行具有最小值的列.例如,这是我的矩阵(只需使用matrix(sample(12),nrow = 3)
生成).对于矩阵,我希望有一个向量(3,4,1)
来表示列号,该列号包含每行中的最小值.我该怎么办?该问题可以重复,但我找不到答案.
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
推荐答案
使用max.col
:
max.col(-mat)
# [1] 3 4 1
这篇关于在r中找到具有最低值的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!