I want to get three .gif image files test.1.gif, test.2.gif, & test.3.gif by using a loop. The code I tried is like this: x=c(0, 1, 2, 3, 4) y=c(1, 2, 3, 4) for(i in 1:3) { x11() jpeg("test.i.gif") plot(x, y) dev.off() } but I only could get one image file, test.i.gif. How can I get three image files? Thanks.
On Fri, 27 Feb 2004 13:09:40 -0800 (PST) Susan Lin wrote:> I want to get three .gif image files test.1.gif, > test.2.gif, & test.3.gif by using a loop. The code I > tried is like this: > x=c(0, 1, 2, 3, 4) > y=c(1, 2, 3, 4) > for(i in 1:3) > { > x11() > jpeg("test.i.gif")This should be jpeg(paste("test.", i, ".gif", sep = "")) also look at help(paste). hth, Z> plot(x, y) > dev.off() > > } > but I only could get one image file, test.i.gif. How > can I get three image files? > > Thanks. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Susan Lin > Sent: Saturday, February 28, 2004 10:10 AM > To: R-help at stat.math.ethz.ch > Subject: [R] a loop question > > I want to get three .gif image files test.1.gif, > test.2.gif, & test.3.gif by using a loop. The code I > tried is like this: > x=c(0, 1, 2, 3, 4) > y=c(1, 2, 3, 4) > for(i in 1:3) > { > x11() > jpeg("test.i.gif") > plot(x, y) > dev.off() > > } > but I only could get one image file, test.i.gif. How > can I get three image files?How about (I haven't tried it) something like: jpeg(paste("test.", i, ".gif", sep = "") -------------------------------------------- Ko-Kang Kevin Wang, MSc(Hon) SLC Stats Workshops Co-ordinator The University of Auckland New Zealand -------------------------------------------- Ko-Kang Kevin Wang, MSc(Hon) SLC Stats Workshops Co-ordinator The University of Auckland New Zealand