我想讀取一個txt文件並執行一些文本挖掘方法。當我在R中使用tm包時,我收到了很多錯誤消息。例如,如果我想關聯最常用的單詞,我只有NA。下面是代碼,我至今使用:txt文件在R包中生成NA tm(textmining)
library(tm)
doc <- c("word1 word1 word2 word1 word2 word3 word1 word2 word3 word4 word1 word2 word3 word4 word5")
Corpus <- Corpus(VectorSource(doc))
Corpus <- tm_map(Corpus, stripWhitespace)
Corpus <- tm_map(Corpus, tolower)
Corpus <- tm_map(Corpus, removeWords, stopwords("english"))
Corpus <- tm_map(Corpus, removePunctuation)
tdm <- TermDocumentMatrix(Corpus)
#Plotting correlation of Terms
plot(tdm, terms = findFreqTerms(tdm, lowfreq = 2, Inf)[1:3], CorThreshold = 0.1)
在那之後,我得到了以下錯誤消息:
Error in if (all(from == t(from))) "undirected" else "directed":
missing value where TRUE/FALSE needed
O.K.進行調查,我用下面的代碼,其是findAssocs的)的工序,通過步驟方法(:
terms <- findFreqTerms(tdm, lowfreq = 2)[1:3]
m <- as.matrix(t(tdm[terms,]))
m
cor(m)
然而,我得到以下輸出:
word1 word2 word3
word1 NA NA NA
word2 NA NA NA
word3 NA NA NA
從我的觀點來看,文字有問題,但我對這種奇怪的行爲沒有任何解釋。我的問題是,如果有人解決了這個問題。 My R(2.15.2)在Mac系統上運行(x86_64-apple-darwin9.8.0/x86_64(64位))。
非常感謝!
參見[這](http://stackoverflow.com/questions/13575180/how-to-change-the-language-of-檢查errors-in-r)將語言錯誤更改爲英語。 – agstudy 2013-04-24 07:49:40