考虑一个数字向量, a <- c(75,26,65,27,97,72)
和一个矩阵 10x6 矩阵 b
1.4168709 0.6253624 2.08645202 2.9475645 1.29317931 0.80175442
0.3669328 0.851852 0.57428245 2.8542504 1.40075478 0.01745655
6.1173956 1.6848444 1.05468424 0.3382552 1.1428774 0.41141215
2.8203602 0.9573334 0.22131122 0.4406137 0.07209113 0.17910147
0.102152 0.1779387 0.94915127 0.3516491 1.48272109 0.06037996
0.3124434 0.4892484 2.04443039 0.1251463 2.41507973 1.25367433
0.2154152 0.3951161 0.60410084 0.7551265 0.55764737 1.17793564
1.5451135 0.7764766 3.11515773 1.3519765 0.08916275 1.39969422
0.4018092 0.2432501 0.06470464 2.6173665 0.24696145 5.27272096
1.1683212 0.1258633 0.19431636 0.4160356 1.61775945 0.78849181
输入
b <- structure(c(1.41687091749774, 0.366932780481875, 6.11739562418232,
2.8203601760972, 0.102152034174651, 0.312443420290947, 0.215415194164962,
1.54511345728281, 0.401809234172106, 1.16832122397808, 0.625362366437912,
0.851851973640633, 1.68484436153414, 0.957333435262454, 0.177938693314666,
0.489248352590948, 0.395116138737649, 0.776476616387118, 0.243250062223524,
0.125863284132781, 2.08645202020619, 0.57428245106712, 1.05468423915856,
0.221311220899224, 0.949151266561806, 2.04443038991633, 0.604100843891501,
3.11515773070936, 0.0647046443940286, 0.194316359037562, 2.94756450172152,
2.85425036383753, 0.338255227074493, 0.440613748457464, 0.351649099495262,
0.125146273523569, 0.755126529331219, 1.35197646259786, 2.61736654663894,
0.416035552509129, 1.29317931454153, 1.40075477585735, 1.14287740174205,
0.072091125883162, 1.48272109049815, 2.41507973323081, 0.557647368015562,
0.0891627511009574, 0.246961451135576, 1.61775945491138, 0.80175441955164,
0.0174565480835137, 0.411412146408111, 0.179101474117488, 0.0603799588836676,
1.25367433010839, 1.17793564121695, 1.39969422101023, 5.27272095591089,
0.788491813423944), .Dim = c(10L, 6L))
我的问题是如何将向量 a 与矩阵 b 逐行相乘。我知道b%*%a
会做什么。
我正在尝试做这样的事情
75*1.4168709 + 26*0.6253624 + 65*2.08645202 + 27*2.9475645 + 97*1.29317931 + 72*0.80175442
75*0.3669328 + 26*0.851852 + 65*0.57428245 + 27*2.8542504 + 97*1.40075478 + 72*0.01745655
很快
任何建议都非常感谢。