Re: [R] Calculating the mean of values in tables using formulae

2011-07-22 Thread Daniel Malter
Check the *apply() series of functions. tapply() will do what you want. attach(mtcars) tapply(hp,list(cyl,gear),mean) HTH, Daniel Mark Alen wrote: > > I know commands like xtabs and table allow a user to do cross-tabulation > For example the following command generates a pivot table that sh

[R] Calculating the mean of values in tables using formulae

2011-07-22 Thread Mark Alen
I know commands like xtabs and table allow a user to do cross-tabulation 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   812 0 2 > We