de_xtr - 1 year ago 50

R Question

I am new to R programming and while reading a book I came across this mathematical operation involving a matrix in R - "%*%". I could not understand what the following operation does. Can someone help me please?

`> y`

[,1] [,2]

[1,] 1 3

[2,] 2 4

> y%*%y

[,1] [,2]

[1,] 7 15

[2,] 10 22

>

Answer Source

`%*%`

multiplies two matrices.

In your example:

```
[,1] [,2]
[1,] 1*1+3*2 1*3+3*4
[2,] 2*1+4*2 2*3+4*4
```

I.e. `[1,1]`

is a result of sum-product of first row elements (1 and 3) with first column elements (1 and 2): `1*1+3*2`

.