tm Corpus: tm_map function does not change the corpus
我是 R 中 tm 包的新手。我正在尝试使用 tm_map 函数创建文档术语矩阵,但显然传递给 tm_map(Corpus, function, lazy=TRUE) 的函数并未应用于语料库。具体来说,文档不会转换为小写。 R Studio 不显示任何错误或警告。
我在这里搞砸了什么吗?这可能是一些问题吗?
1
2 3 4 5 6 7 8 9 10 11 12 13 14 |
library(tm)
setwd(“…”) filenames <- list.files(getwd(), pattern=”*.txt”) docs <- Corpus(VectorSource(files)) docs <- tm_map(docs, function(x) iconv(enc2utf8(x$content), sub =””), lazy=TRUE) #to lower case |
感谢您的建议!
这是一个简单的修复。将转换为小写的代码移到 iconv(…) 之前。
这行得通:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
library(tm)
setwd(“”) # Read in Files # Lower Case # Convert |
来源:https://www.codenong.com/42365214/