Here’s essentially the same as Mark’s answer, but quite 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’re using knitr with LaTeX, this is arguably a task for LaTeX, not for R: R provides the raw data, LaTeX is in charge of formatting. I would probably just tell knitr to issue numbers wrapped inside a macro – \readable{42}
– and then do the conversion with this macro (untested, and requires the package siunitx
):
\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}}