我需要以类似循环的行为保存一些图形和 Rdata。我做了一个简短的例子来说明我需要做什么。我的问题是在我的代码中,图形只是相互覆盖,所以我想我在动态命名它们时遇到了麻烦。
for (i in seq(from = 100, to = 2000, by = 100)){
x <- rnorm(1:3000)
x <- x[seq(from=1, to=length(x),i)]
e=0
d <- matrix(ncol = 1, nrow = 91)
for (f in seq(from=1, to=10,by=0.1)) {
e=e+1
d[e] <- sum(abs(x)^f)
}
x = data.frame(d);
names(x)='V1';
x$V2 = seq(from = 1, to = 10, by = 0.1);
pdf("C:/Users/x.pdf", height=6, width=6)
ggplot(x, aes(x=x$V2, y = x$V1)) +
geom_line(alpha=1)
dev.off()
save.image(file = "output.Rdata")
}
谢谢!