title: Error in if (!all(o)) { : missing value where TRUE/FALSE needed R
body: <p>I try to create a sentiment analysis system using word2vec and logistic multinomial regression.</p>
  
  <p>For this, I tried to do like the author did here : <a href="http://analyzecore.com/2017/02/08/twitter-sentiment-analysis-doc2vec/" rel="nofollow noreferrer">http://analyzecore.com/2017/02/08/twitter-sentiment-analysis-doc2vec/</a></p>
  
  <p>Here the R code : </p>
  
  <pre><code>library(tidyverse)
  library(text2vec)
  library(caret)
  library(glmnet)
  library(ggrepel)
  
  Train_classifier &lt;- read.csv('IRC.csv',header=T, sep=";")
  Test_classifier &lt;- read.csv('IRC2.csv',header=T, sep=";")
  
  # select only 4 column of the dataframe
  
  Train &lt;- Train_classifier[, c("Note.Reco", "Raison.Reco", "DATE_SAISIE", "idpart")]
  Test &lt;- Test_classifier[, c("Note.Reco", "Raison.Reco", "DATE_SAISIE", "idpart")]
  
  #delete rows with empty value columns
  subTrain &lt;- Train[rowSums(Train == '') == 0,]
  subTrain$ID &lt;- seq.int(nrow(subTrain))
  
   subTrain
        DATE_SAISIE    idpart    ID  Raison.Reco  Note.Reco
  2      19/03/2014 102853645     1  Good         0
  3      19/03/2014   1072309     2  Not good     2
  4      19/03/2014    191391     3  very good    9
  6      19/03/2014     14529     4  not comment  8
  7      19/03/2014 100065501     5  very professional  9
  8      19/03/2014 102261392     6  very good  1
  9      19/03/2014 102734704     7  good  10
  10     19/03/2014   1004397     8  not very good  10
  
  # # replacing class values
  subTrain$Note.Reco = ifelse(subTrain$Note.Reco &gt;= 0 &amp; subTrain$Note.Reco &lt;= 4, 0, ifelse(subTrain$Note.Reco &gt;= 5 &amp;
  subTrain$Note.Reco &lt;= 6, 1, ifelse(subTrain$Note.Reco &gt;= 7 &amp; subTrain$Note.Reco &lt;= 8, 2, 3)))
  
  
  subTest &lt;- Test[rowSums(Test == '') == 0,]
  subTest$ID &lt;- seq.int(nrow(subTest))
  
  #Data pre processing
  #Doc2Vec
  
  prep_fun &lt;- tolower
  tok_fun &lt;- word_tokenizer
  
  subTrain[] &lt;- lapply(subTrain, as.character)
  it_train &lt;- itoken(subTrain$Raison.Reco, 
                     preprocessor = prep_fun, 
                     tokenizer = tok_fun,
                     ids = subTrain$ID,
                     progressbar = TRUE)
  
  
  
  subTest[] &lt;- lapply(subTest, as.character)
  it_test &lt;- itoken(subTest$Raison.Reco, 
                     preprocessor = prep_fun, 
                     tokenizer = tok_fun,
                     ids = subTest$ID,
                     progressbar = TRUE)
  
  
  #creation of vocabulary and term document matrix
    ### fichier  d'apprentissage
  vocab_train &lt;- create_vocabulary(it_train)
  vectorizer_train &lt;- vocab_vectorizer(vocab_train)
  dtm_train &lt;- create_dtm(it_train, vectorizer_train)
  
  
    ###  test data
  
  
  
  vocab_test &lt;- create_vocabulary(it_test)
  vectorizer_test &lt;- vocab_vectorizer(vocab_test)
  dtm_test &lt;- create_dtm(it_test, vectorizer_test)
  
  ##Define  tf-idf model 
  
  tfidf &lt;- TfIdf$new()
  # fit the model to the train data and transform it with the fitted model
  dtm_train_tfidf &lt;- fit_transform(dtm_train, tfidf)
  dtm_test_tfidf &lt;- fit_transform(dtm_test, tfidf)
  
  glmnet_classifier &lt;- cv.glmnet(x = dtm_train_tfidf,
                                 y = subTrain[['Note.Reco']], family = 'multinomial',type.multinomial = "grouped")
  </code></pre>
  
  <p>When I run this code I get this error : </p>
  
  <blockquote>
  <pre><code>&gt; glmnet_classifier &lt;- cv.glmnet(x = dtm_train_tfidf,
  +                                y = subTrain[['Note.Reco']], family = 'multinomial',type.multinomial = "grouped")
  Error in if (!all(o)) { : missing value where TRUE/FALSE needed
  </code></pre>
  </blockquote>
  
  <p>Any idea please? </p>
  
  <p>Thank you</p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>The problem come from this line line @Edward Moseley said in his comment :</p>
  
  <pre><code>subTrain[] &lt;- lapply(subTrain, as.character)
  </code></pre>
  
  <p>But when I delete it and I move to this line : </p>
  
  <pre><code>it_train &lt;- itoken(subTrain$Raison.Reco, 
                     preprocessor = prep_fun, 
                     tokenizer = tok_fun,
                     ids = subTrain$ID,
                     progressbar = TRUE)
  </code></pre>
  
  <p>I get this error : </p>
  
  <pre><code>Error in UseMethod("itoken") : 
    no applicable method for 'itoken' applied to an object of class "factor"
  
  
  
  
  subTrain
  &gt; subTrain
        Note.Reco
  1             3
  2             3
  3             2
  4             3
  5             3
  6             1
  7             3
  8             1
  9             2
  10            3
  11            3
  12            3
  13            3
  14            2
  15            2
  16            3
  17            3
  18            2
  19            3
  20            2
  21            2
  22            2
  23            0
  24            0
  25            2
  26            3
  27            3
  28            0
  29            0
  30            2
  31            3
  32            3
  33            3
  34            3
  35            0
  36            1
  37            2
  38            1
  39            3
  40            3
  41            3
  42            1
  43            3
  44            2
  45            3
  46            3
  47            2
  48            3
  49            3
  50            2
  51            1
  52            1
  53            2
  54            3
  55            3
  56            2
  57            2
  58            3
  59            2
  60            1
  61            3
  62            0
  63            2
  64            2
  65            3
  66            0
  67            1
  68            3
  69            2
  70            2
  71            3
  72            2
  73            2
  74            2
  75            3
  76            2
  77            2
  78            3
  79            3
  80            3
  81            3
  82            2
  83            2
  84            1
  85            0
  86            2
  87            0
  88            3
  89            3
  90            3
  91            2
  92            1
  93            2
  94            1
  95            3
  96            3
  97            2
  98            2
  99            3
  100           3
  101           0
  102           2
  103           2
  104           0
  105           2
  106           3
  107           2
  108           2
  109           2
  110           3
  111           3
  112           2
  113           2
  114           2
  115           3
  116           3
  117           2
  118           3
  119           3
  120           3
  121           3
  122           2
  123           3
  124           2
  125           2
  126           0
  127           3
  128           3
  129           0
  130           3
  131           0
  132           1
  133           3
  134           2
  135           0
  136           1
  137           3
  138           1
  139           3
  140           3
  141           3
  142           2
  143           2
  144           3
  145           2
  146           2
  147           3
  148           1
  149           1
  150           3
  151           2
  152           2
  153           3
  154           2
  155           3
  156           2
  157           3
  158           3
  159           3
  160           0
  161           2
  162           1
  163           3
  164           3
  165           1
  166           2
  167           2
  168           3
  169           2
  170           3
  171           3
  172           3
  173           2
  174           2
  175           3
  176           3
  177           0
  178           3
  179           2
  180           3
  181           0
  182           3
  183           3
  184           2
  185           3
  186           3
  187           1
  188           3
  189           1
  190           2
  191           2
  192           3
  193           3
  194           3
  195           2
  196           2
  197           3
  198           2
  199           0
  200           3
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ... &lt;truncated&gt;
  1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
  2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ... &lt;truncated&gt;
  3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ... &lt;truncated&gt;
  4                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ... &lt;truncated&gt;
  5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
  6                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ... &lt;truncated&gt;
  7  
  </code></pre>
  
  <p>I see this "truncated value" in the dataframe, is it normal?</p>