我有兩個數據幀佔用和數據。我想通過在職業數據框中添加一列來匹配佔領數據中的每個職業並分配核心應用類。在R中匹配句子和句子?
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模糊匹配」,直到你找到你喜歡的東西。 – MrFlick