最佳R,在data.frame通过从另一个data.frame值+动态列
基本上,我有一个表数据和一个较小的表词汇替换值。 我想有是,该词汇数值很好地对数据值映射。而这一功能中,以这样一种方式,它可以被用来+/- dynamicaly
考虑:
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
通缉的结果:
V1____V2___sex__V4__V5_
abc abc f abc 123
abc abc m abc 123
abc abc m abc 123
我”什么已经
replace_by_vocabulary <- function(dt,voc,col_name){
dt[,col_name] <- tolower(dt[,col_name])
**** something something ***
return(dt)
}
我怎么想使用它...
dt <- replace_by_vocabulary(dt,vocabulary1,"sex")
dt <- replace_by_vocabulary(dt,vocabulary2,"date")
dt <- replace_by_vocabulary(dt,vocabulary3,"mood")
[R中VLOOKUP类型的方法](http://stackoverflow.com/questions/18645222/vlookup-type-method-in-r) –