Print to PDF in a for loop
问题 I want to loop over a plot and put the result of the plot in a PDF . The following code is used to do this: What this does is loop 3 times and plot 3 different plots from the iris dataset. Then it should save it to the C:/ drive. The PDF files are created, but are corrupted. for(i in 1:3){ pdf(paste("c:/", i, ".pdf", sep="")) plot(cbind(iris[1], iris[i])) dev.off() } 回答1: To drawn lattice plots on the device, one needs to print the object produced by a call to one of the lattice graphics