Rank of a matrix in R

36,175

Solution 1

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]

Solution 2

http://cran.r-project.org/web/packages/Matrix/Matrix.pdf, page 101

http://cran.r-project.org/web/packages/matrixcalc/matrixcalc.pdf, page 12

Share:
36,175
user1274212
Author by

user1274212

Updated on July 13, 2022

Comments

  • user1274212
    user1274212 almost 2 years

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