Re: [R] Problem on Matrix multiplication

From: Michal Bojanowski <m.j.bojanowski_at_fss.uu.nl>
Date: Thu 15 Jun 2006 - 20:34:15 EST

Hi,

AKS> But when I want to get [transpose(weight)][s][weight] using following AKS> syntax,

AKS> t(weight)%*%s%*%weight

I guess 'weight' and 's' are dataframes and you need matrices. Like here:

x <- rnorm(8)
s <- matrix(rnorm(64), ncol=8)

t(x) %*% s %*% x # this is OK

d <- as.data.frame(x)
t(d) %*% s %*% d # this is your error

You can use data.matrix() to convert dataframes to matrices:

t( data.matrix(d) ) %*% s %*% data.matrix(d) # again OK

HTH, Michal

~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~

Michal Bojanowski
ICS/Utrecht
Utrecht University
Heidelberglaan 2; 3584 CS Utrecht
Room 1428
m.j.bojanowski@fss.uu.nl



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jun 15 20:37:49 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 15 Jun 2006 - 22:10:48 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.