Learn R Programming

smdc (version 0.0.2)

conv2Freq: Conversion from Matrix to Frequency Distribution

Description

This function convert matrix to frequency distribution.

Usage

conv2Freq(tmpMatrix, wordClass, breaks)

Arguments

tmpMatrix
Matrix.
wordClass
Classes of each row of matrix.
breaks
Class devision vector.

Value

Frequency distribution matrix.

Examples

Run this code

## The function is currently defined as
function (tmpMatrix, wordClass, breaks) 
{
    freqDist <- matrix(0, nrow = length(breaks) - 1, ncol = ncol(tmpMatrix))
    for (tmp in rownames(tmpMatrix)) {
        cat <- wordClass[tmp]
        if (!is.na(cat)) {
            freqDist[cat, ] <- freqDist[cat, ] + tmpMatrix[tmp, 
                ]
        }
    }
    colnames(freqDist) <- colnames(tmpMatrix)
    if (!is.null(names(breaks))) {
        rownames(freqDist) <- names(breaks)[2:length(breaks)]
    }
    return(freqDist)
  }

Run the code above in your browser using DataLab