本文介绍了R:向量乘法矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题:

myvec <- c(1:3)

mymat <- as.matrix(cbind(a = 6:15, b = 16:25, c= 26:35))
mymat
       a  b  c
 [1,]  6 16 26
 [2,]  7 17 27
 [3,]  8 18 28
 [4,]  9 19 29
 [5,] 10 20 30
 [6,] 11 21 31
 [7,] 12 22 32
 [8,] 13 23 33
 [9,] 14 24 34
[10,] 15 25 35

我想将mymat与myvec相乘,并构造新的向量,使

I want to multiply the mymat with myvec and construct new vector such that

sum(6*1, 16*2, 26*3)
sum(7*1, 17*2, 27*3)

....................
sum(15*1, 25*2, 35*3)

对不起,这是一个我不知道的简单问题...

Sorry, this is simple question that I do not know...

拼写错误

推荐答案

R中的%*%运算符进行矩阵乘法:

The %*% operator in R does matrix multiplication:

> mymat %*% myvec
      [,1]
 [1,]  116
 [2,]  122
 ...
[10,]  170

这篇关于R:向量乘法矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-16 06:10