Common Functions Used with Factors
With factors, we have yet another member of the family of
tapply. We’ll look at that function, as well as two other functions commonly used with factors:
The tapply() Function
As motivation, suppose we have a vector
x of ages of voters and a factor
f showing some nonumeric trait of those voters, such as party affiliation (Democrat, Republican, Unaffiliated). We might wish to find the mean ages in
x within each of the party groups.
In typical usage, the call
x as a vector,
f as a factor or list of factors, and
g as a function. The function
g() in our little example above would be R’s built-in
mean() function. If we wanted to group by both party and another factor, ...