|
根据映射关系查找替换
Replace values in a dataframe based on lookup table
https://www.codenong.com/35636315/
https://746923.com/r-use-data-frame-as-lookup-table
根据以上网页的内容, 没有映射关系的,会被赋值NA,再替换NA。
修改代码,一步到位。
new <- data
new[] <-
lapply(data, function(x)
ifelse(is.na(match(x, dmjm$dm)), x, dmjm$jm[match(x, dmjm$dm)]))
Note that I use empty brackets ([]
) in couple cases until keep which structure of new
as it used (a data.frame).
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-4-28 02:51
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社