3

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?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Datackatlon
  • 199
  • 1
  • 4
  • 15
  • What classes are used objects and what is `itoken` actually expecting? – Roman Luštrik Mar 10 '17 at 14:41
  • @RomanLuštrik, I try to di like this in this tutorial http://analyzecore.com/2017/02/08/twitter-sentiment-analysis-doc2vec/?utm_campaign=Submission&utm_medium=Community&utm_source=GrowthHackers.com – Datackatlon Mar 10 '17 at 14:44
  • 2
    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 Mar 10 '17 at 14:48

1 Answers1

4

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)
zx8754
  • 52,746
  • 12
  • 114
  • 209