除非还包括“广告”或“营销”,否则我想摆脱关键字中包含“计划”一词的行。特别是在样本数据集中,应删除包含“hr plan”和“operation plan”的关键字的行。
keyword <- c("advertising plan",
"advertising budget",
"marketing plan",
"marketing budget",
"hr plan",
"hr budget",
"operation plan",
"operation budget")
indicator <- c(1,0,0,1,1,1,0,1)
sample <- cbind(keyword,indicator)
答案 0 :(得分:2)
如果不使用花哨的正则表达式,我可能只是想要结合你的两个规则:
sample[!(grepl("plan", sample[,"keyword"]) &
(!grepl("marketing|advertising", sample[,"keyword"]))),]
# keyword indicator
#[1,] "advertising plan" "1"
#[2,] "advertising budget" "0"
#[3,] "marketing plan" "0"
#[4,] "marketing budget" "1"
#[5,] "hr budget" "1"
#[6,] "operation budget" "1"
答案 1 :(得分:1)
这是使用正则表达式和type_info = np.iinfo(new_type)
a = type_info.min
b = type_info.max
return np.all((data >= a) & (data <= b))
包的可能解决方案。正如评论中所提到的,我将stringr
扩展了2个值。基本上你想用正则表达式来检测哪个indicator
没有“计划”,或者以“广告”或“营销”开头。 HTH
keyword