I created a list of title names and then modified a function i found here
mcollist<-list(A,B,C,D)# where A,B,C and D are dataframes
namelist<-c("A","B","C","D")
for(i in 1:length(namelist)){
mypath <- file.path("C:","Users","myname","Desktop","PLOTS",paste("myplot_", namelist[i], ".jpeg", sep = ""))
jpeg(file=mypath)
mytitle = paste("my title is", namelist[i])
multicolplot<-lapply(mcollist,function(data){pairs(data)})##this is a function that is creating multicollinearity plot for multiple
##datasets stored as a list in 'mcollist'.
dev.off()
}
While I get the "number of plots" correct i.e. as many as the names in the list i created. The plots are all of the same dataset. I don't get any error so I'm not sure where the issue is here
The same plot that is being saved multiple times is the last one on which multicolplot function is running on.
EDIT
The same function when applied to save Correlogram, won't work
for(i in 1:length(data1)){
mypath <- file.path("C:","Users","myname","Desktop","PLOTS",paste("myplot_", data1[i], ".jpeg", sep = ""))
jpeg(file=mypath)
mytitle = paste("Correlogram for", data1[i])
{
a`cf(data1[,i],na.action=na.pass,main=paste(names(data1)[i]))`
}
dev.off()
}
Data1 is a dataframe containing variables (as columns) on which I wish to run acf test as implemented by the following code:
acf(data1[,i],na.action=na.pass,main=paste(names(data1)[i]))
It is running acf on each column of data1 ignoring 'na' values and then pasting the names from data1 column names
I get the following error:
Error in jpeg(file = mypath) : unable to start jpeg() device
In addition: Warning messages:
1: In jpeg(file = mypath) :
unable to open file 'C:/Users/myname/Desktop/PLOTS/myplot_c(0.62, 1.13, 2.53, -0.97, 0.82, 3.9, 1.77, -0.85, 2.57, -1.1, 1.67, 1.38, 0.67, 2.73, 1.32, 0.84, 0.65, 0.96, -0.86, 0.97, 0.7, 1.05, -0.26, 0.04, 1.14, 1.46, 2.08, 1.2, 2.53, 2.49, 2.79, 2.16, 2.3, -1.29, 0.49, -1.28, 1.78, 1.26, -1.71, -3.89, 1.45, 2.2, 2.26, 1.13, 2.82, 0.83, -0.91, -0.02, 0.79, 0.71, 0, 1.37, 2.81).jpeg' for writing
2: In jpeg(file = mypath) : opening device failed
Thanks for your help
mcollist
? If it is a list of data sets, did you mean to typemcollist[[i]]
?lapply
by justpairs(mcollist[[i]])
, because you're already iterating through the list elements usingfor
loop