user3314305
user3314305

Reputation: 13

print column where max value is found

        [,1]      [,2]        [,3]      [,4]     [,5]
[1,]  5.4290131  5.352399 -0.07464946 10.720809 6.378636
[2,]  5.9674506 10.546944  5.05475087 -1.224233 9.573862
[3,]  1.9928987 -3.220822  0.51927476  1.927324 2.786789
[4,] -0.9927265  6.690987  1.35911091 -2.490596 2.105721

how do I print the entire column in where the max value is found?? In this case I would like to print column [,4]

Also I would like to do print the entire row in where the max value is found. [1,]

Upvotes: 1

Views: 143

Answers (1)

Sven Hohenstein
Sven Hohenstein

Reputation: 81693

You can use

mat[, which.max(apply(mat, 2, max))]

where mat is the name of your matrix.

Upvotes: 1

Related Questions