An Eager Avocado

Eager Avocado

I give myself very good advice, but I very seldom follow it.

Digit count

,

Recursive function

digit_count <- function(number,count=1) {
        if (number < 10) {return(count)}
    return(digit_count(number %/% 10, count=count+1))
}

Timing

system.time(for (i in 1:10000) digit_count(1000))
##    user  system elapsed 
##   0.052   0.000   0.051
# user  system elapsed 
#  0.056   0.000   0.057 
system.time(for (i in 1:10000) str_length(as.character(1000)))
## Error: could not find function "str_length"
## Timing stopped at: 0 0 0.001
# user  system elapsed 
#  0.036   0.000   0.036