Best
Basically, I've a table data and a smaller table vocabulary. What I would like to have is, that the values of the vocabularies well be mapped on the data values. And this within a function, in such a way that it can be used +/- dynamicaly
Given:
dt : data.csv
V1____V2___sex__V4__V5_
abc abc jeny abc 123
abc abc eric abc 123
abc abc bob abc 123
vocabulary1: sex.csv
old___new
jeny f
eric m
bob m
Wanted Result:
V1____V2___sex__V4__V5_
abc abc f abc 123
abc abc m abc 123
abc abc m abc 123
What I've
replace_by_vocabulary <- function(dt,voc,col_name){
dt[,col_name] <- tolower(dt[,col_name])
**** something something ***
return(dt)
}
How I would like to use it ...
dt <- replace_by_vocabulary(dt,vocabulary1,"sex")
dt <- replace_by_vocabulary(dt,vocabulary2,"date")
dt <- replace_by_vocabulary(dt,vocabulary3,"mood")