The tapply() function is one of several "apply" functions in R that allow a function to operate on data repeatedly. The function tapply() applies a function to groups of observations within a vector (e.g., a variable in a data frame) where the groups correspond to the levels of some factor. For example, we might have a vector of heights for men and women in the same vector; tapply() allows us to compute the mean, median, max, or some other function of height for each gender. In SAS, we called such an operation "by processing", and tapply() is one of several functions we will study that facilitates such calculations. In this video we introduce tapply() and illustrate it with examples. This function is good to know for its own sake, but it also serves as a useful introduction to several other similar functions in R.
This topic is important and this video is essential viewing for the course.