Essentially, this is the same as Marks, but a bit more concise:
numbers = c('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten') readable = function (x) ifelse(x < 11, numbers[x + 1], x)
> readable(sample(1:20, 10)) [1] "20" "12" "13" "seven" "ten" "11" "17" "eight" "16" "18"
Although if you are using knitr with LaTeX, this is probably the task for LaTeX and not for R: R provides raw data, LaTeX is responsible for formatting. I will probably just say that knitr will output the numbers enclosed inside the macro - \readable{42} - and then do the conversion with this macro (unchecked and requires the siunitx package):
\newcommand*\readable[1]{% \ifcase#1 zero\or one\or two\or three\or four\or five\or six\or seven\or eight\or nine\or ten\else\num{#1}}
Konrad Rudolph
source share