How about this? unletter <- function(word) { gsub('-64',' ',paste(sprintf("%02d",utf8ToInt(tolower(word)) - 96),collapse='')) } unletter("abc") [1] "010203" unletter("Aw") [1] "0123" unletter("I walk to school") [1] "09 23011211 2015 190308151512" --Hans