Skip to content
Prev 327712 / 398502 Next

Plot a series of plots without using a loop

Hello,

There's a bug in the line

for (i in 1:length(dim(somdata.xyf$codes$X)[2]))

length() is always 1, you can use simply 1:dim(...)[2] or even simpler

for(i in 1:ncol(somdata.xyf$codes$X))

As for a way without a loop, you could use ?sapply:

sapply(1:ncol(somdata.xyf$codes$X), function(i) plot(...))

But I believe the loop is far more readable, and preferable.

Rui Barradas

Em 31-07-2013 00:25, Ben Harrison escreveu: