After spending much time developing the proper corpus (e.g. stopwords, tf-idf) I created a dtm
in the tm
package and ran my topic model.
I then proceeded to compare the topics to some document level covariates of interest, only to learn that stm
allows you to estimate models using document-level covariates of interest.
I have successfully converted my dtm
to a dfm
in quanteda
and would like to add my covariates to the dfm
before converting to a stm
.
I have a data.frame
with my covariates of interest which share the same row.id
as the dfm
.
I am looking for a solution to merge the covariates from the data.frame
with the dfm
.
I have tried:
docvars
and metadoc
in quanteda
to no avail.
For example,
docvars(dfm, docnames(dfm)) <- df$covariate
Any help would be greatly appreciated!