Search notes:

R function: tapply

tapply(elems, group_index, fun… )
tapply first partitions the elements of elems according to the indices in group_index, then applies function fun on each group's elements.
The following example defines items with that each have a color and a size. With tapply, the average (mean) size for each group is calculated and returned:
items <- data.frame (
  color = c('red', 'blue', 'blue', 'red', 'green', 'green', 'yellow', 'blue', 'green', 'yellow', 'red', 'blue', 'blue', 'green', 'red', 'yellow'),
  size  = c(   5 ,    10 ,    11 ,    6 ,     15 ,     16 ,      20 ,     9 ,     13 ,      18 ,    7 ,    14 ,     8 ,     13 ,    6 ,      18 )
)

items$color == 'red'

tapply(items$size, items$color, mean)
# 
#     blue    green      red   yellow 
# 10.40000 14.25000  6.00000 18.66667 
Github repository about-r, path: /functions/tapply.R
In SQL, this example would roughly correspond to the following statement. (Never mind the fact that SQL apparently does not define a mean aggregate function).
select
   color,
   mean(size)
from
   df
group by
   color;

Misc

The t in tapply stands for table.

See also

Other apply functions
Index to (some) R functions

Index