Maarölli
Maarölli

Reputation: 385

How to convert integer into a string literal?

Is there a function to transform integers into their English equivalents? I.e. to achieve the transformation:

some_function(1) = 'one'

Upvotes: 1

Views: 503

Answers (2)

Sven Hohenstein
Sven Hohenstein

Reputation: 81693

Use the english package

library(english)
english(1:10)
# [1] one   two   three four  five  six   seven eight nine  ten  

Upvotes: 5

Roland
Roland

Reputation: 132706

some_function <- function(i) {
     stopifnot(i %in% 1:9)
     lookup <- c("one", "two", "three",
                 "four", "five", "six",
                 "seven", "eight", "nine")
     lookup[i]
}

Modify as needed.

Upvotes: 3

Related Questions