I know that commands like xtabs and table allow the user to do cross tabs
For example, the following command generates a pivot table that shows the number of cars that have the same number of gears and cylinders.
> xtabs(~cyl+gear, data = mtcars) gear cyl 3 4 5 4 1 8 2 6 2 4 1 8 12 0 2 >
We can expand the formula so that it can show the sum of horse power for cars in each bunker
> xtabs(hp~cyl+gear, data = mtcars) gear cyl 3 4 5 4 97 608 204 6 215 466 175 8 2330 0 599 >
Now I wonder, is it possible to calculate the average horsepower for cars in each bunker? e.g. something like this xtabs(mean(hp)~cyl+gear, data = mtcars)
source share