2016-07-05 88 views
1

我正在尝试对推文进行情感分析。虽然这样做的话的前处理,创造一个矩阵,我得到了以下错误:r中的词干:缺失值

Error in if (any(lens > lim)) stop("There is a limit of ", lim, "characters on the number of characters in a word being stemmed") : 
missing value where TRUE/FALSE needed 

从14215个鸣叫,我煮下来到产生错误的具体鸣叫,但都没有得到线索如何防止再次发生此错误。 由于其出错的鸣叫是(和代码重现错误):

library(RTextTools) 
tweet<-"demonio leg edge sexy we get it u vape PLEASE COME TO NA SOON I HAVE A LUCIEL READY FOR U dominos" 
all_tweets= create_matrix(tweet, language="english", minWordLength = 3, 
         removeStopwords=TRUE, removeNumbers=TRUE, # we can also removeSparseTerms 
         stemWords=TRUE,removePunctuation = TRUE,removeSparseTerms = 0) 

首先,我想理解的错误 - 为什么会发生,然后我的愿望是这将使我的方法防止发生此错误 - 通过选择和删除这样的推文或通过编辑我的create_matrix函数?

+0

嗨,哪个版本你有(R/RTextTools包)。在Windows 64,R 3.2.2和RTextTools 1.4.2上,我无法在您提供的文本上重现错误。 –

+0

我正在使用R版本3.3.0和RTextTools 1.4.2 – user3109578

+0

也许是区域设置或编码的问题。 @lukeA建议似乎也是一种可能性。无论如何,你的代码在这里很有魅力。 –

回答

1

这个错误来自执行

wordStem(
    c("demonio", "leg", "edge", "sexy", 
    "get", "u", "vape", "please", 
    "come", NA, "soon", "luciel", 
    "ready", "u", "dominos") 
) 
# Error in if (any(lens > lim)) stop("There is a limit of ", lim, "characters on the number of characters in a word being stemmed") : 
# missing value where TRUE/FALSE needed 

也许这是一个错误。字符串“NA”似乎被标记为NA(缺失值)。

作为一种变通方法,使用

library(tm) 
all_tweets <- DocumentTermMatrix(
    Corpus(VectorSource(tweet)), 
    control = list(
    wordLengths = c(3, Inf), 
    stopwords=TRUE, 
    removeNumbers=TRUE, 
    stemming=TRUE, 
    removePunctuation = TRUE 
) 
) 

sessionInfo()

R version 3.3.0 (2016-05-03) 
Platform: x86_64-w64-mingw32/x64 (64-bit) 
Running under: Windows 7 x64 (build 7601) Service Pack 1 

locale: 
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252 
[4] LC_NUMERIC=C     LC_TIME=German_Germany.1252  

attached base packages: 
[1] stats  graphics grDevices utils  datasets methods base  

other attached packages: 
[1] RTextTools_1.4.2 SparseM_1.7  

loaded via a namespace (and not attached): 
[1] Rcpp_0.12.5   splines_3.3.0  MASS_7.3-44   tau_0.0-18   prodlim_1.5.5  tm_0.6-2   
[7] lattice_0.20-33  foreach_1.4.3  caTools_1.17.1  tools_3.3.0   nnet_7.3-11   parallel_3.3.0  
[13] grid_3.3.0   ipred_0.9-5   glmnet_2.0-5  e1071_1.6-7   iterators_1.0.8  class_7.3-14  
[19] survival_2.39-4  randomForest_4.6-12 Matrix_1.2-6  NLP_0.1-9   lava_1.4.3   bitops_1.0-6  
[25] codetools_0.2-14 rsconnect_0.4.3  maxent_1.3.3.1  rpart_4.1-10  slam_0.1-32   tree_1.0-36 
+0

是的。锻炼完美(但需要库(SnowballC))。 – user3109578