[R] table, xyplot, names, & loops

Daniel Malter
Tue, 25 Aug 2009 17:44:18 -0000

Just plotting the mean is not very informative (at least not more
informative than providing the same information in a table). If you want to
show some of the distributional properties of height for each Age_group x
City pair, try box-and-whisker plots ?bwplot

Imagine you have four age categories and five cities.

 Age=rep(0:3,each=25)
 City=rep(0:4,20)

 e=rnorm(100)

#Create a dependent variable
 Height=(Age-1)+(City-1)+(Age-1)*(City-1)+e

#Box whisker plot of Height by Age category for each City
bwplot(Height~factor(Age)|factor(City))

Daniel

-------------------------
cuncta stricte discussurus
-------------------------

-----Urspr?ngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von w_poet
Gesendet: Tuesday, August 25, 2009 1:17 PM
An: r-help at r-project.org
Betreff: [R] table, xyplot, names, & loops


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.

I also tried constructing a new array with mean Height for each Age_group,
factored by City, but couldn't find any way of doing this without using
loops.

I'm sure there must be an elegant way of plotting this in R without
resorting to loops, but I can't find any hints in the online manuals.

Thanks for any tips~


--
View this message in context:
http://www.nabble.com/table%2C-xyplot%2C-names%2C---loops-tp25138552p2513855
2.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org 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.