gofastr
gofastr copied to clipboard
Make an as_dfm
Seems useful to have as_dfm
for quanteda package as this gains popularity as a data structure solution in R. People will expect to be able to convert to this format easily and quanteda provides mechanisms to do this.
This gives you converting dtm to dfm where dtm
is a DocumentTermMatrix object:
as.dfm.DocumentTermMatrix <- function(x, ...){
as.dfm(
Matrix::sparseMatrix(
i = x$i,
j = dtm$j,
x = x$v,
dimnames = list(seq_len(nrow(x)), colnames(x))
)
)
}
I don't think there's a way to convert to dfm from DocumentTermMatrix directly.
Also seems useful to make q_dfm
& q_dfm_stem
right out of the box as well?? This avoids the step of converting to dfm then to dtm and back to dfm.
This is related: https://github.com/quanteda/quanteda/issues/1222 for handling the conversion