Dear all r-users, I am getting a big problem with matrix multiplication suppose I have,> weightWeight 1 1067640 2 8871500 3 42948778 4 127583735 5 22000000 6 44000000 7 56850000 8 23805662 and,> sa b c d e f g h a 402493.18 -133931.62 461483.3 -94042.86 674493.8 -1493713.2 - 714081.5 -1320551.6 b -133931.62 192766.63 -414674.4 -36700.74 -276595.3 798034.6 382661.6 883478.4 c 461483.25 -414674.43 1618660.4 660949.18 988526.5 -2795048.7 - 1483334.1 -1761234.9 d -94042.86 -36700.74 660949.2 1053310.43 -300291.4 -98814.9 - 263716.7 1130451.3 e 674493.80 -276595.33 988526.5 -300291.35 3090869.8 -3017747.3 - 1766040.6 -2295605.0 f -1493713.19 798034.60 -2795048.7 -98814.90 -3017747.3 10558734.1 4415620.8 6200897.7 g -714081.51 382661.62 -1483334.1 -263716.67 -1766040.6 4415620.8 2593947.5 2341455.0 h -1320551.58 883478.39 -1761234.9 1130451.26 -2295605.0 6200897.7 2341455.0 7756557.3 But when I want to get [transpose(weight)][s][weight] using following syntax, t(weight)%*%s%*%weight I got error: Error in t(weight) %*% s %*% weight : requires numeric matrix/vector arguments Can anyone please tell me that where my error is? Thanks and regards, [[alternative HTML version deleted]]
It looks like weight and s are data frames, not vectors/matrices as required (and as the error message tells you). Dan Daniel Nordlund Bothell, WA> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] > On Behalf Of Arun Kumar Saha > Sent: Wednesday, June 14, 2006 11:10 PM > To: r-help at stat.math.ethz.ch > Subject: [R] Problem on Matrix multiplication > > Dear all r-users, > > I am getting a big problem with matrix multiplication > > suppose I have, > > > weight > Weight > 1 1067640 > 2 8871500 > 3 42948778 > 4 127583735 > 5 22000000 > 6 44000000 > 7 56850000 > 8 23805662 > > and, > > s > a b c d e > f g h > a 402493.18 -133931.62 461483.3 -94042.86 674493.8 -1493713.2 - > 714081.5 -1320551.6 > b -133931.62 192766.63 -414674.4 -36700.74 -276595.3 798034.6 > 382661.6 883478.4 > c 461483.25 -414674.43 1618660.4 660949.18 988526.5 -2795048.7 - > 1483334.1 -1761234.9 > d -94042.86 -36700.74 660949.2 1053310.43 -300291.4 -98814.9 - > 263716.7 1130451.3 > e 674493.80 -276595.33 988526.5 -300291.35 3090869.8 -3017747.3 - > 1766040.6 -2295605.0 > f -1493713.19 798034.60 -2795048.7 -98814.90 -3017747.3 10558734.1 > 4415620.8 6200897.7 > g -714081.51 382661.62 -1483334.1 -263716.67 -1766040.6 4415620.8 > 2593947.5 2341455.0 > h -1320551.58 883478.39 -1761234.9 1130451.26 -2295605.0 6200897.7 > 2341455.0 7756557.3 > > > But when I want to get [transpose(weight)][s][weight] using following > syntax, > > t(weight)%*%s%*%weight > > > I got error: > > Error in t(weight) %*% s %*% weight : requires numeric matrix/vector > arguments > > Can anyone please tell me that where my error is? > > Thanks and regards, > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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
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