1

I'm new to R and i'm trying to pass a 3 character as a function variable that begins with a zero, but it concatenates the zero. How do I pass it as a 3 characters beginning with zero?

  some_fun(007)
  
  some_fun(x){
    x
  }

  7
alz chow
  • 19
  • 4

1 Answers1

0

Perhaps, we need to pass a string. If it is a numeric value with leading zeros, it will be dropped as the numeric don't allow it. An option is to convert to character class

some_fun <- function(x) {
              sprintf('%03d', x)
 }
some_fun(7)
#[1] "007"
akrun
  • 874,273
  • 37
  • 540
  • 662