[R] Can this be vectorized?
Marc Feldesman
feldesmanm at pdx.edu
Tue May 1 17:50:35 CEST 2001
I want to produce some boxplots (and qqnorm plots) for each of a series of
groups. It is easy to produce the boxplots or qqplots by groups using
either by() or tapply(), but the moment that I want unique labels for each
boxplot, I seem to be stuck using a for loop to achieve the effect.
For example:
tapply(fstat$femur, fstat$race, boxplot)
by(fstat$femur, fstat$race, boxplot)
gives nicely unlabelled boxplots.
but I'm struggling with how to pass the labelling arguments to either
tapply or by:
e.g.
tapply(fstat$femur, fstat$race, function(x) boxplot(x, main=????))
(nothing obvious comes to mind here that extracts the levels of fstat$race
but:
for (i in 1:3) {
boxplot(fstat[as.numeric(fstat$race)==i, "femur"], main=levels(fstat$race)[i])
}
gives exactly what I want.
It probably isn't worth the effort to avoid the loop above, but curiosity
compels me to ask whether there is a way to vectorize the extraction of the
levels from within an apply, tapply, by....?
Thanks.
=====================
Dr. Marc R. Feldesman
Professor and Chairman
Anthropology Department
Portland State University
1721 SW Broadway
Portland, Oregon 97201
email: feldesmanm at pdx.edu
phone: 503-725-3081
fax: 503-725-3905
http://web.pdx.edu/~h1mf
PGP Key Available On Request
======================
"Anyway, no drug, not even alcohol, causes the fundamental ills of society.
If we're looking for the source of our troubles, we shouldn't test people
for drugs, we should test them for stupidity, ignorance, greed and love of
power." P.J. O'Rourke
Powered by Optiplochoerus and Windows 2000 (scary isn't it?)
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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