Matrix expression causes error “requires numeric/complex matrix/vector arguments”?

不羁岁月 提交于 2019-11-27 14:37:49

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

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

But this gives a 7x7 matrix which can't be added to the 3x3 identity matrix that you're 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 don't feel confident about the difference between a matrix and data.frame.

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

I couldn't 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.

Matrix expression causes error “requires numeric/complex matrix/vector arguments”?

This error occurs because you are passing a String in vector and As string cannot be multiply. matrix(c('1','2','2','1'), nrow=2,ncol=2,byrow=TRUE)->> J

To correct it pass a numeric/complex arguments it works. matrix(c(1,2,2,1), nrow=2,ncol=2,byrow=TRUE)->> j

then use this t = j %*% t(j) //it will print the multiplication of matrix transpose and matrix. print(t)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!