簡體   English   中英

R錯誤GoogleNewsSource繼承(x,“ Source”)不是TRUE

[英]R Error GoogleNewsSource inherits(x, “Source”) is not TRUE

我正在使用tm和tm.plugin.webmining包嘗試閱讀一些Goggle新聞並對它們進行一些基本分析。 但是,我從一開始就面臨一個問題:

googleNewsCorpus <- Corpus (GoogleNewsSource("Google"))

我收到以下錯誤:

Error: inherits(x, "Source") is not TRUE

請幫忙。 我正在使用R版本3.1,R Studio版本0.98.1091,tm版本0.6和tm.plugin.webmining版本1.2.2。

解決了! 我將結果轉換為WebCorpus:

gnewsCorpus <- WebCorpus(GoogleNewsSource("Google"))

我現在可以將其用於后續的“ tm”分析:

data <- tm_map(gnewsCorpus,removeWords, stopwords("english"))
...

但是,一個相關的問題是:在完成所有分析之后,創建了一個術語文檔矩陣,並使用hclust()進行了聚類,如何將新聞標題放入聚類樹狀圖中?

...
tdm <- TermDocumentMatrix(data)
h <- hclust(dist(t(tdm),method="cosine"))
plot(h)

這樣也可以回答相關查詢:

newsheadings <- character(length(gnewsCorpus))
for (i in 1:length(gnewsCorpus)){
  newsheadings[i] <- gnewsCorpus[[i]]$meta$heading
}
...
plot(h, labels = newsheadings)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM