【发布时间】:2017-04-07 19:04:55
【问题描述】:
我有两个数据框占用和数据。我想将数据中的每个职业与职业相匹配,并通过在职业数据框中添加一列来分配对应的类。
occupation <- c("I am Civil Engineer human being", "Graphic Designer too late", "Architect by profession", "Sales Manager Bank", "Love my profession of Professor", "NA")
occupation <- data.frame(occupation)
data <- data.frame(class = c("Engineers","Designer","Artist","Designer","Poetry""Banker and Prof"), Occupation = c("Civil Engineer", "Graphic Designer", "Painter","Poetry","Architect(prof)", "Sales Manager Bank"))
我想要这样的输出
occupation class
I am Civil Engineer human being Engineers
Painter Architect Poetry Artists
Graphic Designer too late Designers
Architect by Painter profession Architect
Sales Manager Bank Banker and Prof
Love my profession of Professor NA
NA NA
我试过了,但它响应什么
occupation$value <- sapply(data$occupation, grepl, x = occupation)
【问题讨论】:
-
尝试搜索“r 模糊匹配”,直到找到你喜欢的东西。