prop: Convert Raw Numeric Matrix or Data Frame to Proportions

View source: R/prop.R

propR Documentation

Convert Raw Numeric Matrix or Data Frame to Proportions

Description

Convert a raw matrix or dataframe to proportions/percents. Divides each element of a column by the column sum.

Usage

prop(mat, digits = 2, percent = FALSE, by.column = TRUE, round = FALSE)

Arguments

mat

A numeric matrix or dataframe.

digits

Integer; number of decimal places to round.

percent

logical. If TRUE output given as percent. If FALSE the output is proportion.

by.column

logical. If TRUE applies to the column. If FALSE applies by row.

round

logical. If TRUE rounds the returned values (controlled by digits).

Value

Returns a matrix with proportionally scaled values.

Examples

## Not run: 
y <- wfdf(DATA$state, DATA$person, stopwords = c("your", "yours"), 
    margins = TRUE)
prop(wfm(y), 4)[1:10, ]        #as a proportion
prop(wfm(y), 4, TRUE)[1:10, ]  #as a percentage
heatmap(prop(wfm(y), 4))
wdstraj <- word_stats(rajSPLIT$dialogue, rajSPLIT$person)
prop(wdstraj$gts[, -1], 5)[1:15, 1:6]

## End(Not run)

qdap documentation built on May 31, 2023, 5:20 p.m.

Related to prop in qdap...