-1

I want to store a array of numbers in a 3-digit format as 001 ,002 etc. But when i try to use the auto fill it gets stored as 1,2,3 only.

How do i store a array of numbers as 001,002 etc rather than 1,2,3 in R programming ? I did search but not able to find a suitable answer.

KRam1802
  • 31
  • 1
  • 11

1 Answers1

2

Use sprintf like this:

# create the n variable which is the number of numbers stored in the array
n <- 10
vector <- sprintf("%03d", 1:n)

this returns:

[1] “001” “002” “003” “004” “005” “006” “007” “008” “009” “010”   
karirogg
  • 128
  • 8
  • [Here](http://www.cookbook-r.com/Strings/Creating_strings_from_variables/) is a good site to learn more about the sprintf command – karirogg May 17 '15 at 17:28