I would suggest not using a data.frame
for a dictionary, since the basic object in R
, a vector, is a dictionary by default.
dict <- c('primo', 'secondo', 'testo')
names(dict) <- c('first', 'second', 'text')
Then to "tanslate"
x
, where x
might be "second"
, you simply use:
dict[[x]]
You dont even need a wrapper function.
If you want to translate in the opposite direction, use
name(dict)[names(dict) %in% x]
Or you can flip the dictionary
dict.flip <- names(dict)
names(dict.flip) <- dict