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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "Smit," == Smit, A, Albertus, Dr <ajsmit at botzoo.uct.ac.za> writes:> I need to do a series of histograms for each of the codes, > levels or factors in 'site'. [...] > Is there are more elegant way to do this without having to > use the fr.wt[1:82] bit? One way you can do it is to use tapply, as in > tapply( ft.wt, site, hist ) An alternative that is even better, IMHO, is to use the lattice package, which is very slick :-) Mike -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Smit, A, Albertus, Dr
2001-Dec-06 15:22 UTC
[R] Histograms per coding variable - labelling the plots
Dear all Thank you to all who replied to the question regarding plotting histograms for a series of coding variables. The tapply() function seems to work well, and so does the lattice package. Kaspar Pflugshaupt also pointed out the following:> With some tricks, you can even have a title with the respective label over > each plot... but I forgot how I did this.Does anyone know how to do this? Thank you again, 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._