[R] using hist() with tapply()

Kevin Bartz kbartz at loyaltymatrix.com
Wed Sep 1 22:48:50 CEST 2004


Hi Paul,

I think lattice's histogram will do what you want, and in a friendlier
manner. Take a look at this example:

require(lattice)
a <- data.frame(draw = as.vector(mapply(rnorm, rep(100, 4), rep(0, 4),
1:4)),
                sd   = factor(paste("sd =", rep(1:4, each = 100))))

Go ahead and examine "a": "draw" contains the aggregate results of random
draws with four different standard deviations, while "sd" tells you which
value of the standard deviation generated the draw. Naturally, I'd want four
histograms as my result. With lattice, I'd do

histogram(~ draw | sd, a)

and get back a sensible result.

Was this what you were looking for?

Kevin

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Schwarz,Paul
Sent: Wednesday, September 01, 2004 11:45 AM
To: r-help at stat.math.ethz.ch
Subject: [R] using hist() with tapply()

Hi,

I've been passing the hist() function to tapply() to quickly generate
histograms based on the list of factors supplied to tapply().  However, I
have not figured out how to generate titles for each of the histograms,
which paste in the unique values of the list factors as part of the
histogram title.  I'm hoping that someone can tell me how to do this.

Thanks for your time and consideration,

-Paul Schwarz

______________________________________________
R-help at 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




More information about the R-help mailing list