[R] List dimention labels to plots of components

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Aug 20 16:27:46 CEST 2004

White, Charles E WRAIR-Wash DC wrote:

> My goal is more efficient code for something I anticipate doing a lot.
> My example code from my first message works because I insert a seemingly
> redundant recording of Dose & Treatment in the list generated in the
> "by" command. Since Dose & Treatment are already recorded in the
> dimensions of the list, I would like to pass those dimensions into the
> function executed by lapply. That may or may not be possible.
> # Append the following code to my message of 8/19
> # Dose & Treatment go to list without separate user code to insert them
> dat.lm2<-by(dat,list(Dose=dat$Dose,Treatment=dat$Treatment),
>             function(x) lm(Response~Sex,data=x))
> dimnames(dat.lm2)
> dat.lm2["Low","B"]
> # lapply uses dimnames to select objects but does not appear to pass 
> # dimnames with object
> lapply(dat.lm2,dimnames)
> lapply(dat.lm2,names)
> lapply(dat.lm2,function(x) print(x)[1:13])
> Thanks for your help. 
> Chuck 

Just one example:

mapply(function(x, y) plot(x[[1]], main = y),
        outer(rownames(dat.lm2), colnames(dat.lm2), paste, sep="/"))

Uwe Ligges

More information about the R-help mailing list