r - Explanation for sprintf("%03d", 7) functionality? -
i trying write functions in r aim read multiple .csv files. named 001.csv, 002.csv, ... 332.csv.
with paste managed construct names 1.csv, 2.csv , on, i'm having difficulty adding leading zeroes. there's hint construction sprintf("%03d", 7) required, have no idea why , how works.
so can explain following statement can does?
sprintf comes c , formatting rules taken well. see ?sprintf in r or this or this reference learn subject in detail. here i'll briefly outline what's magic behind it.
"%03d" formatting string, specifies how 7 printed.
dstandsdecimal integer(notdouble!), says there no floating point or that, regular integer.3shows how many digits printed number have. more precisely, number take at least 3 digits:7__7(with spaces instead of underscores),1000remain1000, there no way write number 3 digits.0before3shows leading spaces should replaced zeroes. try experimentingsprintf("%+3d", 7),sprintf("%-3d", 7)see other possible modifiers (they called flags).
Comments
Post a Comment