Let's take this code:
library(doBy)
tab <- summaryBy(x ~ A + B, df)
It computes the mean of x
for each combination of A & B.
How can I create a 2D table out of tab
with A
in rows and B
in columns, so that the intersection of a row and column gives the mean of x
for a group having given combination of A & B?
I would skip the intermediate step and use a function that is designed to deliver what you want, namely
tapply
. Using agsudy's data:If you really wanted to use the intermediate step you can also use
tapply
with either theI
orc
functions to do the rearrangement: