Читать книгу The Big R-Book - Philippe J. S. De Brouwer - Страница 67
4.3.4.4 Matrix Arithmetic
ОглавлениеMatrix arithmetic allows both base operators and specific matrix operations. The base operators operate always element per element.
Basic arithmetic on matrices works element by element:
M1 <- matrix( c(10:21), nrow = 4, byrow = TRUE) M2 <- matrix(c(:11), nrow = 4, byrow = TRUE) M1 + M2 ## [,1] [,2] [,3] ## [1,] 10 12 14 ## [2,] 16 18 20 ## [3,] 22 24 26 ## [4,] 28 30 32 M1 * M2 ## [,1] [,2] [,3] ## [1,] 0 11 24 ## [2,] 39 56 75 ## [3,] 96 119 144 ## [4,] 171 200 231 M1 / M2 ## [,1] [,2] [,3] ## [1,] Inf 11.000000 6.000000 ## [2,] 4.333333 3.500000 3.000000 ## [3,] 2.666667 2.428571 2.250000 ## [4,] 2.111111 2.000000 1.909091