r – Matrix expression causes error requires numeric/complex matrix/vector arguments?

r – Matrix expression causes error requires numeric/complex matrix/vector arguments?

To get the matrix multiplication to work, you need to convert the data.frame (presumably thats what da is) to a matrix:

t(da)%*%as.matrix(da)

But this gives a 7×7 matrix which cant be added to the 3×3 identity matrix that youre using. Do you mean something like:

ma=diag(7)+t(da)%*%as.matrix(da)

You may like to have a look at An Introduction to R if you dont feel confident about the difference between a matrix and data.frame.

Just in addition, you get this error if you attempting to pass a data frame where a matrix should be.

r – Matrix expression causes error requires numeric/complex matrix/vector arguments?

See also this solution: https://bugs.r-project.org/bugzilla/show_bug.cgi?id=16607

I couldnt figure out what was wrong with combat, so I tried to run PCA (function prcomp) on my dataset. R kept telling me that the input is not a matrix, even though when checking the class of the input object, it did say matrix and mode numeric. After restarting my IDE (Architect in my case), everything was running fine with combat and with PCA.

Leave a Reply

Your email address will not be published.