[R] lapply, plot and additional arguments

Petr Pikal petr.pikal at precheza.cz
Tue Sep 26 17:40:32 CEST 2006


Dear all

Hopefully somebody will know the answer.

I have some list

x <- data.frame(a = 1:9, beta = exp(-4:4), logic = rep(c(TRUE,FALSE), 
c(5,4)))
x.l <- split(x, x$logic)
plot(x.l$a, x.l$beta)

and I want to plot lines color coded according to logic variable

lapply(x.l, function(x, ...) lines(x$a, x$beta, col=1:2))
lapply(x.l, function(x,...) lines(x$a,x$beta), col=1:2)
lapply(x.l, function(x,...) lines(x$a,x$beta, ...), col=1:2)

Well, lapply seems to ignore my best attempts to persuade it to use 
different colours for each part of x.l list.

Anybody knows how to code different colours when using lapply for 
such plotting?

At present time I use a loop but maybe lapply could do it too.

Best regards.
Petr

Petr Pikal
petr.pikal at precheza.cz



More information about the R-help mailing list