Replacing the year with English words in R

I need to preprocess a speech transcript for forced alignment. However, I am having difficulty replacing the year with a text representation. For example, 1984 should be replaced with "nineteen eighty four". I tried the replace_number function for the qdap package. The package is awesome, but instead it replaces 1984 with "nineteen eighty four." Are there other features from any R packages that I can try? Thank!

+3


source to share


1 answer


you can split them into two parts and separately convert each part to symbol representation:

year = 1984
paste(
    replace_number(substr(as.character(year), 1, 2),
    replace_number(substr(as.character(year), 3, 4)
) 

      



it will give nineteen eightyfour

+5


source







All Articles