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.

  • d stands decimal integer (not double!), says there no floating point or that, regular integer.
  • 3 shows how many digits printed number have. more precisely, number take at least 3 digits: 7 __7 (with spaces instead of underscores), 1000 remain 1000, there no way write number 3 digits.
  • 0 before 3 shows leading spaces should replaced zeroes. try experimenting sprintf("%+3d", 7), sprintf("%-3d", 7) see other possible modifiers (they called flags).

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -