[R] loop
    arun 
    smartpink111 at yahoo.com
       
    Thu Feb 21 20:49:49 CET 2013
    
    
  
Hi,
Try this:
You can save it as either individual jpeg files or as a single pdf document containing all the figures.
set.seed(54)
res<- matrix(sample(20:60,25,replace=TRUE),ncol=5)
res1<- res[,-1]
b<- res[,1]
#jpeg
 mypath<- file.path("/home/arunksa111/Trial", paste("myplot_",names1,".jpg",sep=""))
for(i in seq_along(mypath)){
lapply(seq_len(ncol(res1)),function(i){
jpeg(file=mypath[i]) 
 matplot(res1[,i],type="l",col="grey")
 lines(b,lwd=2,col="black")
 dev.off()
 })
 }
#pdf
mypath1<- file.path("/home/arunksa111/Trial", "myplot.pdf")
pdf(file=mypath1) 
lapply(seq_len(ncol(res1)),function(i){
 matplot(res1[,i],type="l",col="grey")
 lines(b,lwd=2,col="black")
 })
 dev.off()
________________________________
From: eliza botto <eliza_botto at hotmail.com>
To: "smartpink111 at yahoo.com" <smartpink111 at yahoo.com> 
Sent: Thursday, February 21, 2013 1:16 PM
Subject: loop
Dear Arun,
i have a matrix called "res" of 124 rows and 12 columns. i want to draw curve of each column against the first column and want to save that file at a specific location in my computer.
i used the following commands but they are not working
names1<-1:123
 b<-res[,1]
mypath<-file.path("/R/SAVEHERE",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,lwd=2,col="black")
  dev.off()
   })
 }
i hope you can find the error
thanks in advance
elisa
-------------- next part --------------
A non-text attachment was scrubbed...
Name: myplot.pdf
Type: application/pdf
Size: 6444 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130221/ca45132e/attachment.pdf>
    
    
More information about the R-help
mailing list