What is a way to count the number of digits of a numeric object in R including leading zeroes?
For example, I know nchar(x)
will return the number of digits if x
is numeric but what about instances in which x
includes leading zeros?
Note: Count the number of integer digits does not address the issue of leading zeros.
Example:
x<-7
nchar(7)
[1] 1 #that's fine
x<-07
nchar(07)
[1] 1 #that is NOT fine: I want the value of 2 to appear