9 mtapply()

Being a multivariate version of tapply(), mtapply applies a function over an array by a list of indices.

The two required inputs are the object X and list of indices INDEX. The optional inputs are the function to apply FUN and ..., which passses to mapply. For the first three inputs, see the documentation for tapply()9 for more information; for the fourth, see mapply()10. The output is typically a list of vectors or matrices, depending on the inputs and funciton being passed.

9.0.1 Multivariate tapply()

A <- mtcars[, c('mpg', 'wt', 'disp')]  # Targets.
B <- mtcars[, c('gear', 'am', 'carb')] # Indices.

mtapply(A, B, mean) # Output
## $mpg_by_gear
##        3        4        5 
## 16.10667 24.53333 21.38000 
## 
## $wt_by_am
##        0        1 
## 3.768895 2.411000 
## 
## $disp_by_carb
##        1        2        3        4        6        8 
## 134.2714 208.1600 275.8000 308.8200 145.0000 301.0000