HI Eliza,
I tried the function, on this example dataset in linux system.
res<-list(read.table(text="
???? month????? 2005????? 2006????? 2008????? 2009
????? 1 1.7360776 0.8095275 1.6369044 0.8195241
????? 2 0.6962079 3.8510720 0.4319758 2.3304495
????? 3 1.0423625 2.7687266 0.2904245 0.7015527
????? 4 2.4158326 1.2315324 1.4287387 1.5701019
",sep="",header=TRUE),read.table(text="
?? month?????? 2008????? 2009????? 2010
????? 1? 1.4737028? 2.314878? 2.672661
????? 2? 1.6700918? 2.609722? 2.112421
????? 3? 3.2387775? 7.305766? 6.939536
????? 4? 6.7063592 18.745256 13.278218
",sep="",header=TRUE),read.table(text="
month 2004
1?? 1.34448
2??? 1.86889
3??? 1.43422
4?? 4.33444
",sep="",header=TRUE))
res<-lapply(res,function(x)
{names(x)<-gsub("X","",names(x));x})
names(res)<-c("EE","WW","HH")
names1<-names(res)
?b<-lapply(res,function(x) {if(is.data.frame(x[,-1])) rowMeans(x[,-1]) else
x[,-1]})
mypath<-file.path("/home/arun/Trial1",paste("myplot_",names1,".jpg",sep=""))?
#change the file.path
for(i in seq_along(mypath)){
? lapply(seq_along(res),function(i) {
? jpeg(file=mypath[i])
? matplot(res[[i]][,-1],type="l",col="grey")
? lines(b[[i]],lwd=2,col="black")
? dev.off()
?? })
?}
A.K.
----- Original Message -----
From: eliza botto <eliza_botto at hotmail.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc:
Sent: Monday, December 24, 2012 11:34 AM
Subject: [R] whats wrong in my codes???
Dear R family,i am trying to plot and save, simultaneously,? about 1000. the
name of each plot is contained in "names" file. when i run this loop,
i get an error.
"Error in plot.new() :? Unable to open file
'C:/R/SAVEHERE/myplot_Tak.jpg' for writing". could you please
correct the mistake in the loop?>names<-(names(sp))
>for(a in seq_along(names)){
>mypath <-
file.path("C:","R","SAVEHERE",paste("myplot_",
names[a], ".jpg",sep = ""))
>jpeg(file=mypath)
>for (i in seq(1)){
>b<-lapply(res,function(x) {if(is.data.frame(x[,-1])) rowMeans(x[,-1])
else mean(x[,-1])})
>lapply(seq_along(res), fun)
>fun <- function(i){
>matplot(res[[i]][,-1], type="l",col="grey")
>lines(b[[i]], lwd = 2, col = "black")
>}}
>dev.off()
>}
thanks in advance
eliza ??? ??? ??? ? ??? ??? ?
??? [[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.