That did it!  Thanks Marc.

- Christian

On 11/15/06, Marc Schwartz <[EMAIL PROTECTED]> wrote:
>
> On Wed, 2006-11-15 at 15:03 -0500, Christian Convey wrote:
> > Thanks, let me try to clarify my question with an example.
> >
> > Suppose I have the following data:
> >
> > Gender,   Major,  Course-Grade
> > F, Psy, 3.5
> > F, Psy, 3.1
> > M, Hst, 3.7
> > F,  Hst,  3.6
> > M, Hst,  2.6
> > M, Eng, 3.9
> >
> > I want to compute a table like the following:
> >
> > X-axis: Gender
> > Y-axis: Major
> > Cell(x,y) = mean course-grade
> >
> > So for example, with the data above:
> >
> >           F     M
> > ------------------------
> > Psy |   3.3    NA
> > Hst |   3.6    3.15
> > Eng |  NA    3.9
> >
> > If I were doing this in SQL I'd do it with a cross-tab query.  But the
> world
> > of R still has much unfamiliar terrain :)
> >
> > Thanks,
> > Christian
>
>
> Presuming that DF is a data frame containing your data:
>
> > with(DF, tapply(Course.Grade, list(Major, Gender),
>                   mean, na.rm = TRUE))
>       F    M
> Eng  NA 3.90
> Hst 3.6 3.15
> Psy 3.3   NA
>
>
> See ?tapply and ?with
>
> HTH,
>
> Marc Schwartz
>
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to