[R] table, xyplot, names, & loops

Deepayan Sarkar deepayan.sarkar at gmail.com
Tue Aug 25 23:21:34 CEST 2009


On Tue, Aug 25, 2009 at 10:16 AM, w_poet<stephen.le at ucla.edu> wrote:
>
> Hi R community,
>
> I'm just starting out in R and have a basic question about xyplot and
> tables. Suppose I had a table of data with the following names: Height,
> Age_group, City. I'd like to plot mean Height vs Age_group for each City.
>
> When I try to do the following:
>
>> library(lattice)
>> xyplot(mean(Height) ~ Age_group | City)
>
> of course I get just one data point, the mean Height for all individuals.

One additional pointer: panel.average will do this for you:

xyplot(Height ~ Age_group | City, panel = panel.average)

or

xyplot(Height ~ Age_group | City, type = "a")

As others have pointed out, this is not usually a good idea, but with
a 'groups' argument, this is a cheap way to get an interaction plot.

-Deepayan




More information about the R-help mailing list