Learn R Programming

gamlr (version 0.1)

freq: Frequency Matrix Conversion

Description

Convert a count matrix to the corresponding frequency or term frequency - inverse document frequency matrix.

Usage

freq(x, byrow=TRUE)
tfidf(x, freq=FALSE, offset=1)

Arguments

x
A matrix or simple_triplet_matrix with count entries.
byrow
An indicator for whether you have observation-rows and category-columns, or vice versa.
freq
An indicator for whether x is already a frequency matrix.
offset
An offset added to the total number of documents.

Value

  • freq returns a matrix with row (byrow=TRUE) or column (byrow=FALSE) sums of one. tfidf returns a matrix with entries $f_{ij} \log[ (n+o)/d_j ]$, where $f_{ij}$ is term-j frequency in document-i, $d_j$ is the number of documents containing term-j, and $o$ is your offset.

Examples

Run this code
F <- freq( t(rmultinom(10, 20, c(1/2,1/4,1/8,1/8))) )
tfidf(F, freq=TRUE)

Run the code above in your browser using DataLab