I'm not a advanced R user. I mainly use it for matrix algebra calculation. I have a large matrix (9400 by 9400; 675.1 MB) which I wuold like to invert. I have tried "solve" function and "chol2inv", and I get "Error in...'a' must be a complex matrix". I have also tried with "ginv" function from MASS package, and I got the error message "Error in svd(X) : infinite or missing values in 'x'". I'm sure my matrix does not have null (all zeros) columns or rows. I have checked using: Remove columns with zero values from a dataframe and I get the same matrix. There are not NA values neither, I have tested using Determine the number of NA values in a column. My matrix is numeric and a square matrix ("is.numeric" and "is.matrix" answer TRUE, "dim" 9400x9400). When using "is.singular.matrix" from matrixcalc package, the error message again is Error in determinant.matrix(x, logarithm = TRUE, ...) : 'a' must be a complex matrix . Thus, I don't know why R can't calculate the inversion. Please, do you have any idea how I could solve my problem? Thanks a lot
Asked
Active
Viewed 1,576 times
0
-
Maybe [this question](http://stackoverflow.com/questions/24517384/error-a-must-be-a-complex-matrix) helps... Anyhow, I know you cannot post such a bit matrix, but it is a bit difficult to help you if your problem was reproducible. Also, maybe if you posted your code, even if it is just function calls. Thanks – lrnzcig Apr 05 '16 at 10:16
-
1[Fortune 260](https://cran.r-project.org/web/packages/fortunes/vignettes/fortunes.pdf) might be relevant. – Roland Apr 05 '16 at 10:34
-
1Have you checked `M[!is.finite(M)]`? – Roland Apr 05 '16 at 10:36
-
1I can not reproduce your problem. For me it works: `set.seed(42); x <- matrix(rnorm(9400L*9400L), 9400, 9400); y <- solve(x)` But the calculation takes 1 hour. I used the pure R-commandline without any GUI. – jogo Apr 05 '16 at 11:35
1 Answers
0
The problem was with the infinites. R transforms 0/0 to infinite, but I didn't think about it because the error message was a bit too vague.
Matrix[is.infinite(Matrix)] <- 0
solves my problem.
-
2It might solve the programming problem, but it also might create mathematical problems. – Roland Apr 05 '16 at 13:00