简体   繁体   中英

Replacing year with English words in R

I need to pre-process a speech transcript for forced-alignment. However, I am having difficulty with replacing year with text representation. For example, 1984 needs to be replaced with "nineteen eighty four". I tried the replace_number function of the qdap package. The package is awesome, but it replaces 1984 with "one thousand nine hundred eighty four" instead. Are there other functions from any R packages that may I try? Thanks!

you can split each into two parts and separately convert each part to a character representation:

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

this would yield nineteen eightyfour

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM