我正在使用 tm 包来应用词干提取,并且需要将结果数据转换为数据框。
可以在这里找到解决方案R tm包vcorpus:将语料库转换为数据帧时出错 https://stackoverflow.com/questions/24703920/r-tm-package-vcorpus-corpus-to-dataframe,但就我而言,我的语料库内容为:
[[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 = 字符,因此它适用于我的情况。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)