我有一个数据帧
myDataframe <- data.frame(keyword = c(c("meeting", "laptop"),c("attend a meeting", "fan")))
description <- "I have to attend a meeting."
我必须将描述与数据框架中的column关键字匹配,并返回"出席会议"。有没有办法得到一个特定的输出
使用grepl
将返回myDataframe
中包含description
的关键字
myDataframe <- data.frame(keyword = c(c("meeting", "laptop"),c("attend a meeting", "fan")))
description <- "I have to attend a meeting."
found <- as.logical(lapply(myDataframe$keyword ,
function(x) grepl(x , description)))
myDataframe[found , ]
#> [1] "meeting" "attend a meeting"
由reprex包(v2.0.1)创建于2022-06-02