3
votes

I have a dataframe IRC_DF and I would like to create an iterator over input objects to vocabularies, for this I try to do like this :

it_train <- itoken(IRC_DF$Raison.Reco, preprocessor = prep_fun,
                   tokenizer = tok_fun, ids = IRC_DF$ID, progressbar = FALSE)

But I get this error :

Error in UseMethod("itoken") : 
  no applicable method for 'itoken' applied to an object of class "factor"

Any idea please?

1
What classes are used objects and what is itoken actually expecting? - Roman Luštrik
@RomanLuštrik, I try to di like this in this tutorial analyzecore.com/2017/02/08/twitter-sentiment-analysis-doc2vec/… - Datackatlon
Check the documentation for itoken and write down what classes it expects as input. Then go through each input, check class and confirm that it matches the demanded class. - Roman Luštrik

1 Answers

4
votes

Use the function as.character() on IRC_DF$Raison.Reco before using it on itoken.

  IRC_DF$Raison.Reco <- as.character(IRC_DF$Raison.Reco)      

  it_train = itoken(IRC_DF$Raison.Reco, preprocessor = prep_fun, tokenizer = tok_fun, ids = IRC_DF$ID, progressbar = FALSE)