HelpNeededAgain
HelpNeededAgain

Reputation: 39

How to return maximum value in a matrix in R?

Suppose we have a matrix like this:

               degree        eigenvector     between
degree         1.0000000      0.9404647      0.2435627
eigenvector    0.9404647      1.00000000     0.67371624

I want to return the highest value (not = 1, here 0.94...) and the lowest value (0.243...).

Does anyone know how to do this in R?

Upvotes: 0

Views: 27

Answers (2)

ThomasIsCoding
ThomasIsCoding

Reputation: 101034

Here is another base R option using range + diag

> range(`diag<-`(mat,NA),na.rm = TRUE)
[1] 0.2435627 0.9404647

Upvotes: 0

akrun
akrun

Reputation: 886938

A matrix is a vector with dim attributes. So, we could subset the matrix with a logical vector and get the range to return the min/max values excluding the 1

range(mat[mat != 1])

Upvotes: 0

Related Questions