2017-08-17 20 views
0

このフレーズを使用するまでは、 "TermDocumentMatrix"は良好でした。"TermDocumentMatrix"を使用する場合、 "文字"クラスのオブジェクトに適用される 'meta'の適用可能なメソッドはありません

doc <- tm_map(doc, gsub, pattern = "buy", replacement = "bought") 

ただし、この句を使用すると、「TermDocumentMatrix」はエラーを生成します。

Error in UseMethod("meta", x) : 
no applicable method for 'meta' applied to an object of class "character" 

私は単語の置換が必要です。 私はこのフレーズを使用しました。

私の文書構成は次のとおりです。

1. so I bought it. 
2. I bought the EH AC line in November 2014 
3. 3rd product bought from AC and all no good. 
(skip) 

"TermDocumentMatrix"はどのように使用できますか?

library(tm) 
library(XML) 
library(SnowballC) 

doc<-VCorpus(VectorSource(readLines(file.choose()))) 

doc <- tm_map(doc, stripWhitespace) 

doc <- tm_map(doc, stemDocument) 

doc<-tm_map(doc, content_transformer(tolower)) 

doc<-tm_map(doc, removeWords, stopwords("english")) 

myStopwords <- c(stopwords("english"), "can", "will") 
myStopwords <- setdiff(myStopwords, c("will","can")) 
doc <- tm_map(doc, removeWords, myStopwords) 

doc<-tm_map(doc,removeNumbers) 


#If you omit this step, the error will not appear in "TermDocumentMatrix". 
doc <- tm_map(doc, gsub, pattern = "buy", replacement = "bought") 

doc <- TermDocumentMatrix(doc, control=list(removePunctuation=T)) 

答えて

1

はあなたではなく、任意の文字操作関数にtm_mapに適切なコンテンツトランスを渡す必要があり

doc <- tm_map(doc, content_transformer(function(x) 
    gsub(x, pattern = "buy", replacement = "bought"))) 
関連する問題