[R] group means of multi-way table?
Jim Lemon
jim at bitwrit.com.au
Wed Sep 22 13:24:02 CEST 2010
On 09/22/2010 08:52 AM, Simon Kiss wrote:
> hello, can someone tell me how to generate the means for a data frame
> that looks like this? My data frame has many more variables, but I won't
> bother you with those; these are the one's that I'm interested in.
> Needless to say, z is the variable in which I'm interested. I'd like to
> find out the mean score of z for NDP managers, Conservative managers and
> Liberal managers and then for a few other configurations.
> Ive played around with aggregate, tapply and by, but I can't get it to
> work.
> Cordially,
> Simon Kiss
> mydata=data.frame(cbind(x,y,z))
> mydata$x=as.factor(sample(c("labourers", "salaried", "managers"),
> size=300, replace=TRUE))
> mydata$y=as.factor(sample(c("NDP", "Green", "Liberal", "Conservative"),
> size=300, replace=TRUE))
> mydata$z=as.numeric(sample(1:4, size=300, replace=TRUE))
>
Hi Simon,
This looks a bit like what brkdn in the prettyR package does. If you
want the means nested within subgroups, maybe brkdnNest in the plotrix
package will do what you want.
Jim
More information about the R-help
mailing list