实际上,我想从数据框中提取一些子词列表,我知道我们可以通过语料库提取,但我不想做那些不必要的事情。首先我使用了match和grep,但问题是match只能用于精确匹配,而grep不能用于多个单词。例如:
a=sample(c("Client","offshor","V1fax","12mobile"),10)
z=data.frame(a)
z
a
1 V1fax
2 V1fax
3 12mobile
4 12mobile
5 V1fax
6 clint
7 offshor
8 clint
9 clint
10 12mobile
d=z[is.na(match(tolower(z[,1]),c("fax","mobile","except","talwade"))),]
grep(c("fax","mobile","except","talwade"),tolower(z[,1]))
[1] 1 2 5
Warning message:
In grep(c("fax", "mobile", "except", "talwade" :
argument 'pattern' has length > 1 and only the first element will be used
希望输出结果是:
z
a
1 clint
2 offshor
3 clint
4 clint
正如预期的那样,提取子词列表的有效方法。谢谢。