[R] passing arguments to FUN in lapply
Uwe Ligges
ligges at statistik.uni-dortmund.de
Fri Mar 18 12:46:23 CET 2005
Pingping Zheng wrote:
> Suppose I have a nx2 matrix of data, X, the following code generate
> density estimation for each column and plot them
>
> denlist <- apply(X, 2, density)
> par(mfrow=c(1,2))
> lapply(denlist, plot)
>
> Does anyone know how to change the main title of each density plot
> to "var 1", "var 2" by passing optional argument "main"? I've tried
>
> lapply(denlist, plot, main=c("var 1", "var 2"))
> which generates two same titles "var 1/var 2" and "var 1/var 2"
>
> lapply(denlist, plot, main=list("var 1", "var 2"))
> which generates two same titles "var 1"
>
> Both are not I want.
>
If the title is contained in denlist, you can specify a anonymous
function, if not, use mapply or simply a for() loop.
Uwe Ligges
More information about the R-help
mailing list