Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Automatically Generate Filenames

To generate a series of filename, all with the same base name but having a sequence of numbers, the traditional R approach is to use formatC:

paste("df", formatC(1:10, digits=0, wid=3, format=d, flag="0"), ".dat", sep="")
 [1] "df001.dat" "df002.dat" "df003.dat" "df004.dat" "df005.dat" "df006.dat"
 [7] "df007.dat" "df008.dat" "df009.dat" "df010.dat"

Even easier is using the newer sprintf:

> sprintf("df%03d.dat", 1:10)
 [1] "df001.dat" "df002.dat" "df003.dat" "df004.dat" "df005.dat" "df006.dat"
 [7] "df007.dat" "df008.dat" "df009.dat" "df010.dat"



Copyright © 2004-2005
Brought to you by Togaware.