One can also use
formatC()
with the flag option.
-Don
At 10:47 AM -0200 1/25/10, Henrique Dallazuanna wrote:
Try sprintf:
sprintf("%03d", Sequence)
sprintf("file%03d.dat", Sequence)
On Mon, Jan 25, 2010 at 10:39 AM, Îroutík <zrou...@gmail.com> wrote:
Dear R-users,
I'd like to create filenames in a mask "file000.dat" numbered from 1 to e.g.
123. The last problem I'm dealing with is creating the sequence of numbers
with equal length, i.e. 001, 002,.... 023, 024,.... 122, 123.
The closest I got is by a repetition:
Sequence <- c(1:123)
for(i in c(1:length(Sequence))) {
print(
paste(rep("0",
max(nchar(as.character(Sequence)))-nchar(as.character(Sequence[i]))),
as.character(Sequence[i]),
sep=""))
}
where pasting "0"-replication the missing-times I 'm possibly creating the
desired output. It's just that rep()'s output is not a vector and not
subsequent atoms. and gives "02" and "02" instead of "002".
Any idea hot to correct the function above or suggestions on
file000.dat-mask filename, please?
Thank you for your time.
M
[[alternative HTML version deleted]]
______________________________________________
R-help@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.
--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O
______________________________________________
R-help@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.
--
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
______________________________________________
R-help@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.