gofastr icon indicating copy to clipboard operation
gofastr copied to clipboard

Make an as_dfm

Open trinker opened this issue 7 years ago • 1 comments

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.

trinker avatar Feb 10 '18 16:02 trinker

This is related: https://github.com/quanteda/quanteda/issues/1222 for handling the conversion

trinker avatar Feb 10 '18 17:02 trinker