2017-09-30 5 views
0

を動作しません:Rのremovewords()私はRで初心者だ、と私はここでストップワードに私が作った機能</p> <p>を使用して、いくつかの英語の単語を削除する方法を探しています

cleanfunction <- function(test) { 
test <-removeWords(test,stopwords("en")) 
test<-gsub("\\b[A-z]\\b{1}"," ",test) 
test<-gsub("\\W"," ",test) 
test<-gsub("\\d"," ",test) 
test<-stripWhitespace(test) 

return (test) 
} 

Mdatasub2 <-aggregate(Reviews ~ Product.Name,data =Mdatasub2,FUN=cleanfunction) 

物事はそれが削除されない、ある「」、「だけ」、「これは」「」あなたはあなたのコード内のいくつかの変更を行う必要があり、事前

+0

関数 'removeWords'、' stopwords'および 'stripWhitespace'は' base R'関数ではありません。彼らはどこから来たのか?パッケージとは何ですか?このような場合、適切な 'library'呼び出しでコード例を開始してください。 –

答えて

0

感謝を得ました。

library(tm) 

cleanfunction <- function(test) { 

    ## You can use tm_map but I am keeping gsub function 
    test <-gsub("\\b[A-z]\\b{1}"," ",test) 
    test <-gsub("\\W"," ",test) 
    test <-gsub("\\d"," ",test) 

    # You need to convert your vector to corpus 
    myCorpus <- Corpus(VectorSource(test)) 

    ## You can add any words that you would like to exclude in myStopwords. 
    ## stopwords("english") have some default word list that it would exclude from corpus but not all common words. So, myStopwords will help you to remove certain words that you wish to remove 

    myStopwords <- c("got", "just", "this", "the") 
    myCorpus <- tm_map(myCorpus, removeWords, c(myStopwords, stopwords("english"))) 

    ## Stripping extra white space  
    test <- tm_map(myCorpus, stripWhitespace) 

return (test) 

} 

tm_mapの詳細については、あなたが?tm_mapを使用することができますし、ドキュメントを見て:あなたはtmライブラリと以下のようにtm_map機能を必要としています。

関連する問題