I am looping over a list of dataframes in R and want to use their names as part of the filename I save my plots under.
The code below is my attempt at iterating thro
Slightly different solution:
dataframe1 = data.frame(iv = rnorm(50), dv = rnorm(50))
dataframe2 = data.frame(iv = rnorm(50), dv = rnorm(50))
dataframe3 = data.frame(iv = rnorm(50), dv = rnorm(50))
LIST = list(dataframe1 = dataframe1,
dataframe2 = dataframe2,
dataframe3 = dataframe3)
for(i in 1:length(LIST)){
pdf(file=paste(names(LIST)[i], paste(colnames(LIST[[i]]), collapse="."),
"pdf", sep="."))
plot(LIST[[i]][,1],LIST[[i]][,2],
xlab = colnames(LIST[[i]])[1],
ylab = colnames(LIST[[i]])[2],
main = paste("Plot based on data in", names(LIST)[i]))
dev.off()
}