I want to test the rank of a matrix, is there someone who can recommend a package/function in R for this?
Asked
Active
Viewed 4.1k times
3 Answers
42
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]

Qaswed
- 3,649
- 7
- 27
- 47
3
http://cran.r-project.org/web/packages/Matrix/Matrix.pdf, page 101
http://cran.r-project.org/web/packages/matrixcalc/matrixcalc.pdf, page 12

Andrius Naruševičius
- 8,348
- 7
- 49
- 78
0
You can use the Library pracma: Practical Numerical Math (Provides a large number of functions from numerical analysis and linear algebra, numerical optimization, differential equations, time series, plus some well-known special mathematical functions.).
Install it using the below command in the R console: install.packages("pracma", repos="http://R-Forge.R-project.org") You can use the library then : library(pracma) Rank(Your Matrix object)

Abdul Razzak
- 11
- 3