How to find summary statistics for all unique combinations of factors in a data.frame in R? I want to calculate a summary of a variable in a data.frame for each unique combination of factors in the data.frame. Should I use plyr to do this? I am ok with using loops as opposed to apply() ; so just finding out each unique combination would be enough.
 A: While I think aggregate is probably the solution you are seeking, if you are want to create an explicit list of all possible factor combinations, expand.grid will do that for you. e.g.
> expand.grid(height = seq(60, 80, 5), weight = seq(100, 300, 50),
             sex = c("Male","Female"))
       height weight    sex
1      60    100   Male
2      65    100   Male
... 
30     80    100 Female
31     60    150 Female

You could then loop over each row in the resulting data frame to pull out records from your original data.
A: Here's the plyr solution, which has the advantage of returning multiple summary stats and producing a progress bar for long computes:
library(ez) #for a data set
data(ANT)
cell_stats = ddply(
    .data = ANT #use the ANT data
    , .variables = .(cue,flanker) #uses each combination of cue and flanker
    , .fun = function(x){ #apply this function to each combin. of cue & flanker
        to_return = data.frame(
            , acc = mean(x$acc)
            , mrt = mean(x$rt[x$acc==1])
        )
        return(to_return)
    }
    , .progress = 'text'
)

A: See aggregate and by. For example, from the help file for aggregate:
## Compute the averages according to region and the occurrence of more
## than 130 days of frost.
aggregate(state.x77,
      list(Region = state.region,
           Cold = state.x77[,"Frost"] > 130),
      mean)

A: In addition to other suggestions you may find the describe.by() function in the psych package useful.
It can be used to show summary statistics on numeric variables across levels of a factor variable.
A: In library(doBy) there is also the summaryBy() function, e.g.
summaryBy(DV1 + DV2 ~ Height+Weight+Sex,data=my.data)

A: I personally like cast(), from the reshape package because of it's simplicity: 
library(reshape)
cast(melt(tips), sex ~ smoker | variable, c(sd,mean, length))

