a1<-"NDA|BJP|advani|modi|narendra|namo"
View(src_in)
a coward is incapable of exhibiting love it is the prerogative of the brave mahatma gandhi tropa de paz somostropadepaz
a goal properly set is halfway reached zig ziglar quotes f f ghargharmodi
a modi victory makes it easier for companies and lenders to raise equity on the stock market myvoteformodi
ret_id <- grep(a1,src_in[,4],ignore.case=TRUE)
src_out <- src_in[ret_id,]
View(src_out)
a goal properly set is halfway reached zig ziglar quotes f f ghargharmodi
a modi victory makes it easier for companies and lenders to raise equity on the stock market myvoteformodi
ret_id保存dataframe(src_in)的索引,其中grep命令为true。在src_in第4个字段中存在a1的值(这是包含推文的文本字段)。
但现在由于我们的数据库中出现了这么多搜索词,因此我们以csv文件格式存储。
文件读取命令
df<-read.csv("word.csv")
存储在数据帧中的文件.....命名为df
查看(DF)
1 UPA
2 NCP
3 Gandhi
4 Rahul
5 pappu
6 Sonia
我的问题是如何将df转换为看起来相同的a1格式并添加|在两个单词之间传递给grep命令。
UPA|NCP|Gandhi|Rahul|pappu|Sonia
所以我们可以将grep命令作为参数传递给 a1