On Jul 6, 2009, at 3:16 PM, spime wrote:


Dear R-users,

Recently, I am facing some problems when converting mlbench data into matrix
format.

library(mlbench)
data(BostonHousing)
X<- BostonHousing[,1:13]

If you look at X with str(), you will see it has a factor variable.

y<-BostonHousing[,14]

I want to convert X and y into matrix form. I am getting these obvious
errors...

t(X)%*%y
Error in t(X) %*% y : requires numeric/complex matrix/vector arguments

And since one of the variables was a factor, the result of t(X) (and of as.matrix(X) for that matter ) becomes a character matrix. Perhaps data.matrix(X) will serve better?

t(data.matrix(X))%*%y
               [,1]
crim      25687.104
zn       168607.800
indus    111564.080
chas      12397.000
nox        6094.428
rm        73924.078
age      732581.140
dis       45713.874
rad       93445.100
tax     4287797.600
ptratio  205316.730
b       4208049.505
lstat    119799.159

t(as.matrix(X))%*%(as.matrix(y))
Error in t(as.matrix(X)) %*% (as.matrix(y)) :
 requires numeric/complex matrix/vector arguments

any kind of suggestions will be very helpful.
Thanks.
--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to