Rank of a matrix in R

user1274212 picture user1274212 · Jun 4, 2012 · Viewed 32k times · Source

I want to test the rank of a matrix, is there someone who can recommend a package/function in R for this?

Answer

Qaswed picture Qaswed · May 17, 2016

You can try the function qr ("qr", because it performs a QR decomposition):

#define a matrix for this example
M <- matrix(data = rnorm(12), ncol = 3)

#run the function qr() 
qr(M)$rank

#Alternative: load the Matrix package...
require(Matrix)

#...and run the function rankMatrix()
rankMatrix(M)[1]