11.1 “Common operations”:

  • You can use t()

  • Do aggregate with apply() (see data.frame)

The second argument is specifying the dimensions mostly: 1 for row and 2 for columns but it can be “expanded”.

apply(Titanic, c(1, 3), mean)
##       Age
## Class  Child  Adult
##   1st   1.50  79.75
##   2nd   6.00  65.25
##   3rd  19.75 156.75
##   Crew  0.00 221.25

11.1.1 Binary operators

  • array x array: do an element wise operation

  • array x scalar: scalar is recycled

  • array x vector: the only tricky one it works by recycling column wisely

(B <- matrix(1:6, byrow=TRUE, nrow=2))
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]    4    5    6
B * c(1, 100)
##      [,1] [,2] [,3]
## [1,]    1    2    3
## [2,]  400  500  600