wordcounts_Matrix: Convert a word-counts data frame into document-term matrix

wordcounts_MatrixR Documentation

Convert a word-counts data frame into document-term matrix

Description

This function simply transforms a data frame like that from read_wordcounts into a document-term matrix (in sparseMatrix] format). That is, it converts from long to wide format. This is useful in itself if you want to do matrix manipulations and also a convenient format for interchange with other text-mining packages.

Usage

wordcounts_Matrix(counts)

Arguments

data

frame with columns id, word, weight

Details

In particular, this function is meant to help with packages that expect document-term matrices in the slam package's simple triplet matrix type. A Matrix can be automatically coerced to a simple_triplet_matrix.

Value

sparse link[Matrix]{Matrix} with documents in rows and words in columns, with id and word values as dimnames

See Also

read_wordcounts, instances_Matrix for the same conversion from MALLET's format


agoldst/dfrtopics documentation built on July 15, 2022, 4:13 p.m.