-1

I am using quanteda to create a text corpus and trying to attach metadata, but I keep getting an error. I have used this code before on another dataset, but for some reason it's not working with my current dataset. The code is:

dfm.ineq1 <- corpus(df.ineq$speech, 
                        docnames=df.ineq$speechID, 
                        docvars=select(party))

The error I get is:

Error in select_(.data, .dots = lazyeval::lazy_dots(...)) : object 'party' not found

I also tried to put party in quotes and got this error:

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

The party column is pretty straight forward. The values are:

"Democratic"  "Republican"  "N/A"         "Independent"

Any ideas on what might be going wrong?

help-info.de
  • 6,695
  • 16
  • 39
  • 41
tlev
  • 83
  • 9

2 Answers2

1

An even easier way: use the fact that the corpus constructor method is defined for data.frame objects.

dfm.ineq1  <- corpus(df.ineq, text_field = "speech")

This will automatically load the text field in speech correctly, and include speechID and party as docvars.

Ken Benoit
  • 14,454
  • 27
  • 50
0

I realized I forgot to put the dataframe in the select parenthesis!

dfm.ineq1 <- corpus(df.ineq$speech, 
                        docnames=df.ineq$speechID, 
                        docvars=select(df.ineq, party))
tlev
  • 83
  • 9