R 中的矩阵乘法 - 维数问题

Multiplication of matrices in R - problem of dimensions

我正在尝试乘以 R 中的矩阵:

我知道这个乘法可以完成,但我遇到了一个错误。知道为什么吗?

> d1
     [,1]
[1,]   -3
[2,]    0
[3,]    3

> t1
     [,1] [,2] [,3]
[1,]    2    2    2

> t1 * d1
Error in t1 * d1 : non-conformable arrays

更多细节来自@ThomasIsCoding 评论:

d1<-as.matrix(c(-3,0,3))
t1<-t(as.matrix(c(2,2,2)))


d1 %*% t1
     [,1] [,2] [,3]
[1,]   -6   -6   -6
[2,]    0    0    0
[3,]    6    6    6

来自CRAN关于矩阵乘法的官方文档

A * B is the matrix of element by element products and

A %*% B is the matrix product.

If x is a vector, then

x %% A %% x is a quadratic form.

Link 到文档 HERE.