I've made this function which will convert any 9 or less to a word and will also format large numbers by inserting a comma:
library(english); library(stringr)
reportNumber <- function (number) {
ifelse(number > 9, str_trim(format(number, big.mark= ",", scientific = F)), as.character(english(number)))
}
The function works like this:
reportNumber(c(0, 9, 10, 100, 1000, 10000))
# [1] "zero" "nine" "10" "100" "1,000" "10,000"
But if the number has a decimal point, the function errors:
reportNumber(c(0.1, 9.1, 10.1, 100.1, 1000.1, 10000.1))
I need to make the function test whether a number has a decimal point, and if true, then just print the number unformatted. So the output should simply be:
c(0.1, 9.1, 10.1, 100.1, 1000.1, 10000.1)
# [1] 0.1 9.1 10.1 100.1 1000.1 10000.1