0

I started using R very recently and this is my first post here. I'm still trying to get the hang of things.

Problem: I have a text corpus (corpus1) created to do text analytics using quanteda (primarily). I've also created a docvar (filename) in the corpus which is a common variable for a separate dataframe (df1) I had previously created. I now want to add some (or all) of the variables from the dataframe (df1) to the corpus (corpus1). Note that the filename is unique and common in both dataframe (df1) and (corpus1).

I have tried to use the docvar command but without any success

docvars(corpus1, "file") <- df1

also,

corpus1 <- corpus(txt1(which is a list of the text file), docvars = df1)

My goal is to have the column variables from the dataframe (df1) as docvars in the text corpus (corpus1) which I will need for future analyses.

Thanks in advance for any suggestions and help.

  • Well formatted questions get more attention on Stack-overflow. More info here https://stackoverflow.com/help/how-to-ask – Nigel Savage Jan 27 '20 at 19:43
  • if the rows are a 1:1 match, then `docvars(corpus1) <- df1` should simply replace the existing docvars with your df1 data.frame. – Ken Benoit Jan 27 '20 at 21:52
  • 1
    @KenBenoit, thank you so very much, it worked and exactly what I wanted to do. – Asif Huq Jan 27 '20 at 22:46

0 Answers0