[R] Histograms per coding variable
Ben Bolker
ben at zoo.ufl.edu
Wed Dec 5 13:22:22 CET 2001
Something like
tapply(fr.wt,site,hist,nclass=20)
e.g.:
a <- runif(100)
f <- factor(rep(1:10,rep(10,10)))
par(mfrow=c(3,4))
tapply(a,f,hist)
On Wed, 5 Dec 2001, Smit, A, Albertus, Dr wrote:
> Dear all
>
> I have a dataset that looks like:
>
> fr.wt site
> 1 4400 glen
> 2 235 glen
> 3 225 glen
> ' ' '
> ' ' '
> ' ' '
> 82 550 glen
> 83 550 kom
> 84 550 kom
> ' ' '
> ' ' '
> ' ' '
> 191 820 kom
> 192 2000 soet
> ' ' '
> ' ' '
>
> I need to do a series of histograms for each of the codes, levels or
> factors in 'site'. For the first one, 'glen', I would do:
>
> >hist(fr.wt[1:82], nclass = 20)
>
> for the second, 'kom':
>
> >hist(fr.wt[83:191], nclass = 20)
>
> and so on.
>
> Is there are more elegant way to do this without having to use the
> fr.wt[1:82] bit? I.e., how else can one extract the fr.wt data
> relevant to each code in the 'site' column? If there is, say, 20
> codes in the 'site' column, how can one produce a histogram for each
> without having the retype the hist() bit for each code individually?
>
> I am sure there is an easy solution which I am overlooking.
>
> Thanks for the help,
> Albertus
>
>
> Dr Albertus J. Smit
> Department of Botany
> University of Cape Town
> PO Box Rondebosch
> 7700
> SOUTH AFRICA
> Tel. 689 3032
> Fax. 650 4041
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
318 Carr Hall bolker at zoo.ufl.edu
Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker
Box 118525 (ph) 352-392-5697
Gainesville, FL 32611-8525 (fax) 352-392-3704
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list