[R] handle a sequence of strings with for loop

jonathan_li@agilent.com jonathan_li at agilent.com
Mon Jan 28 21:13:37 CET 2002


Hi all,

I have a string sequence:
"my00", "my01", "my02",...,"my99". 
I would like to process them one by one use a for loop like:

for(i in 0:99){
	str <- paste("my", i, sep="")
	print(str)
}

But this only works with string "my10" to "my99". 
In Python, this problem can be solved by string formating zero fill such as 
print "%02d", i;
which will give 
00, 01, ...,09,10,...,99

I wonder if R has similar solutions?

Regards,
Jonathan


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list