[R] Problem on Matrix multiplication

Michal Bojanowski m.j.bojanowski at fss.uu.nl
Thu Jun 15 12:34:15 CEST 2006


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 at fss.uu.nl



More information about the R-help mailing list