[R] using "by" and indicies

Greg Snow snow at fisher.byu.edu
Mon Mar 18 20:14:44 CET 2002

On Mon, 18 Mar 2002, Jason Turner wrote:

> I sent this to the list last week, and haven't seen it pop up.  Either 
> I deleted it when it did appear, or possibly it was destroyed as 
> spam...?  If it did appear and I somehow missed it, appologies.
> I'm using by() to call pairs(), and would like to put the factor
> level into the title.  A toy example would be something like:
> > d1 <- data.frame(rnorm(100),rt(100,2),sin(1:100))
> > levs <- as.factor(rep(1:5,20))
> > levels(levs) <- c("low","med-lo","med","med-hi","high")
> > by(d1,levs,pairs)
> Is there an elegant way to get "low"..."high" in the main title for
> each plot, without binding "levs" to the data sent to a custom plot 
> function? 

One way is to pass the level info with the data to be plotted:

> d2 <- cbind(d1, levs)
> by(d2,levs,function(x){ tmp <- levels(x[,4])[x[1,4]] ;
+ pairs( x[,1:3], main=paste("Level:",tmp) ) } )

hope this helps,

Greg Snow, PhD                Office: 223A TMCB
Department of Statistics      Phone:  (801) 378-7049
Brigham Young University      Dept.:  (801) 378-4505
Provo, UT  84602              email:  gls at byu.edu

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