dsheuman@rogers.com
2004-Mar-31 14:44 UTC
[R] Removing leading and trailing spaces (string manipulation)
Hi all, I'm running the following code to generate 40 different jpegs based on the resulting data. I'd like the file names to be 'Cluster1.jpeg', however the code write filenames like 'Cluster 1 .jpeg'. How can I get rid of the unwanted spaces? I've looked at ?format and it doesn't seem to work - at least in this context. ################### ClusCount <- 40 datain <- as.data.frame( read.csv("c:\\daclus.csv")) for(i in 1:ClusCount){ mapit <- subset(datain, cluster == i) jpeg(file=paste("c:\\temp\\cluster",format(i),".jpeg"), width = 640, height = 480, pointsize = 12,quality = 300, bg = "white") plot( as.matrix(mapit[,2]), as.matrix(mapit[,3]),xlim=c(-141.6,-52.1),ylim=c(41.5,83.7), type = "p", main = paste("Cluster",i) ) dev.off() } ################### Thanks, Danny
Simon Fear
2004-Mar-31 14:50 UTC
[R] Removing leading and trailing spaces (string manipulation)
I believe all you need to do here is use plain "i" instead of "format(i)" in the jpeg call. Someone is bound to come up with a better generic answer but this should get you up and running for now.> -----Original Message----- > From: dsheuman at rogers.com [mailto:dsheuman at rogers.com] > Sent: 31 March 2004 15:44 > To: R-help at stat.math.ethz.ch > Subject: [R] Removing leading and trailing spaces (string > manipulation) > > > Security Warning: > If you are not sure an attachment is safe to open contact > Andy on x234. > There are 0 attachments with this message. > ________________________________________________________________ > > Hi all, > > I'm running the following code to generate 40 different jpegs > based on the resulting data. I'd like the file names to be > 'Cluster1.jpeg', however the code write filenames like > 'Cluster 1 .jpeg'. > > How can I get rid of the unwanted spaces? I've looked at > ?format and it doesn't seem to work - at least in this context. > > > ################### > ClusCount <- 40 > > datain <- as.data.frame( read.csv("c:\\daclus.csv")) > > for(i in 1:ClusCount){ > mapit <- subset(datain, cluster == i) > jpeg(file=paste("c:\\temp\\cluster",format(i),".jpeg"), > width = 640, height = 480, pointsize = 12,quality = 300, bg = "white") > plot( as.matrix(mapit[,2]), > as.matrix(mapit[,3]),xlim=c(-141.6,-52.1),ylim=c(41.5,83.7), > type = "p", main = paste("Cluster",i) ) > dev.off() > } > ################### > > > Thanks, > > Danny > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >Simon Fear Senior Statistician Syne qua non Ltd Tel: +44 (0) 1379 644449 Fax: +44 (0) 1379 644445 email: Simon.Fear at synequanon.com web: http://www.synequanon.com Number of attachments included with this message: 0 This message (and any associated files) is confidential and\...{{dropped}}
Marc Schwartz
2004-Mar-31 14:53 UTC
[R] Removing leading and trailing spaces (string manipulation)
On Wed, 2004-03-31 at 08:44, dsheuman at rogers.com wrote:> Hi all, > > I'm running the following code to generate 40 different jpegs based on > the resulting data. I'd like the file names to be 'Cluster1.jpeg', > however the code write filenames like 'Cluster 1 .jpeg'. > > How can I get rid of the unwanted spaces? I've looked at ?format and > it doesn't seem to work - at least in this context. > > > ################### > ClusCount <- 40 > > datain <- as.data.frame( read.csv("c:\\daclus.csv")) > > for(i in 1:ClusCount){ > mapit <- subset(datain, cluster == i) > jpeg(file=paste("c:\\temp\\cluster",format(i),".jpeg"), width = 640, > height = 480, pointsize = 12,quality = 300, bg = "white") > plot( as.matrix(mapit[,2]), > as.matrix(mapit[,3]),xlim=c(-141.6,-52.1),ylim=c(41.5,83.7), type > "p", main = paste("Cluster",i) ) > dev.off() > } > ################### > > > Thanks, > > DannyChange the code in your 'jpeg' statement to read: jpeg(file=paste("c:\\temp\\cluster",format(i),".jpeg", sep = ""), ... ^^^^^^^^ You can use the 'sep' argument (which defaults to " ") to eliminate the spaces between the pasted components. See ?paste for more information. HTH, Marc Schwartz
Sean Davis
2004-Mar-31 14:55 UTC
[R] Removing leading and trailing spaces (string manipulation)
Danny, Paste uses sep=" " between arguments as a default. Just include sep="" in the paste call. file=paste("c:\\temp\\cluster",format(i),".jpeg",sep="") Sean On 3/31/04 9:44 AM, "dsheuman at rogers.com" <dsheuman at rogers.com> wrote:> Hi all, > > I'm running the following code to generate 40 different jpegs based on the > resulting data. I'd like the file names to be 'Cluster1.jpeg', however the > code write filenames like 'Cluster 1 .jpeg'. > > How can I get rid of the unwanted spaces? I've looked at ?format and it > doesn't seem to work - at least in this context. > > > ################### > ClusCount <- 40 > > datain <- as.data.frame( read.csv("c:\\daclus.csv")) > > for(i in 1:ClusCount){ > mapit <- subset(datain, cluster == i) > jpeg(file=paste("c:\\temp\\cluster",format(i),".jpeg"), width = 640, height > 480, pointsize = 12,quality = 300, bg = "white") > plot( as.matrix(mapit[,2]), > as.matrix(mapit[,3]),xlim=c(-141.6,-52.1),ylim=c(41.5,83.7), type = "p", main > = paste("Cluster",i) ) > dev.off() > } > ################### > > > Thanks, > > Danny > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >