[R] using hist() with tapply()

Kjetil Brinchmann Halvorsen kjetil at acelerate.com
Wed Sep 1 23:58:59 CEST 2004


Schwarz,Paul wrote:

>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
>
>
>  
>
I can't see it with talpply, but mapply and split works:

test <- rnorm(1000)
fac <- factor( rep(1:5, 200))
par(mfrow=c(2,3))
mapply(hist, split(test, fac), main=levels(fac))


-- 

Kjetil Halvorsen.

Peace is the most effective weapon of mass construction.
               --  Mahdi Elmandjra




More information about the R-help mailing list