[R] coerce mode list?

Jan Seidel jan_seidel at gmx.de
Tue Sep 19 14:09:03 CEST 2000


Mehdi Ghafariyan schrieb:

[...]

> > X1<-X[1:5]
> > W1<-W[1:5,1:5]
> > X1
> [1] 1.250000 1.292308 1.176471 0.937500 1.538462
> > W1
>   VAR00003 VAR00004 VAR00005 VAR00006 VAR00007
> 1        0        1        0        1        0
> 2        1        0        0        0        1
> 3        0        0        0        0        1
> 4        1        0        0        0        0
> 5        0        1        1        0        0
> > Xbar1 <- mean(X1)
> > S1 <- (t(X1 - Xbar1)) %*% W1 %*% (X1 - Xbar1)
> Error in as.double: Cannot coerce mode list to double:
> .Data = list(..
> Dumped
> > S1 <- (t(as.double(X1 - Xbar1))) %*% W1 %*%
> (as.double(X1 - Xbar1))
> Error in as.double: Cannot coerce mode list to double:
> .Data = list(..
> Dumped
>
> I don't understand the error message. Can anyone help?

I guess the problem is you extracted W1 from a dataframe.
Try this:

> W1 <- as.matrix(W[1:5,1:5])
> S1 <- (t(X1 - Xbar1)) %*% W1 %*% (X1 - Xbar1)

Jan Seidel


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list