【发布时间】:2020-05-26 23:23:07
【问题描述】:
我为每个单词创建了列表以从句子中提取单词,例如这样
hello<- NULL
for (i in 1:length(text)){
hello[i]<-as.character(regmatches(text[i], gregexpr("[H|h]ello?", text[i])))
}
但是我有超过 25 个单词列表要提取,那是很长的编码。 是否可以从文本数据中提取一组字符(单词)?
下面只是一个伪集合。
words<-c("[H|h]ello","you","so","tea","egg")
text=c("Hello! How's you and how did saturday go?",
"hello, I was just texting to see if you'd decided to do anything later",
"U dun say so early.",
"WINNER!! As a valued network customer you have been selected" ,
"Lol you're always so convincing.",
"Did you catch the bus ? Are you frying an egg ? ",
"Did you make a tea and egg?"
)
subsets<-NULL
for ( i in 1:length(text)){
.....???
}
预期输出如下
[1] Hello you
[2] hello you
[3] you
[4] you so
[5] you you egg
[6] you tea egg
【问题讨论】:
标签: r extract text-mining