将语料库转换为R中的data.frame [英] convert corpus into data.frame in R
本文介绍了将语料库转换为R中的data.frame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用tm包来应用词干,我需要将生成的数据转换成数据帧。
可以在这里找到一个解决方案。 R tm包vcorpus,语料库到数据框,但在我的情况下,我有语料库的内容如下:
I'm using the tm package to apply stemming, and I need to convert the resulting data into a data frame. A solution for this can be found here R tm package vcorpus, corpus to dataframe, but in my case I have the content of the corpus as:
[[2195]]
i was very impress
而不是
[[2195]]
"i was very impress"
因此,如果我申请
data.frame(text=unlist(sapply(mycorpus, `[`, "content")), stringsAsFactors=FALSE)
结果将是
<NA>.
任何帮助都非常感激!
以下代码作为示例:
sentence <- c("a small thread was loose on the sandals, otherwise it looked good")
mycorpus <- Corpus(VectorSource(sentence))
mycorpus <- tm_map(mycorpus, stemDocument, language = "english")
inspect(mycorpus)
[[1]]
a small thread was loo on the sandals, otherwi it look good
data.frame(text=unlist(sapply(mycorpus, `[`, "content")), stringsAsFactors=FALSE)
text
1 <NA>
推荐答案
应用
gsub("http\\w+", "", mycorpus)
输出有class = character,所以在我的情况下可以工作。
the output has class = character, so it works in my case.
这篇关于将语料库转换为R中的data.frame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文