prop: Compute proportions from numeric vector/matrix/data.frame

View source: R/prop.R

propR Documentation

Compute proportions from numeric vector/matrix/data.frame

Description

prop returns proportion to sum of entire x. prop_col returns proportion to sum of each column of x. prop_row returns proportion to sum of each row of x. Non-numeric columns in the data.frame are ignored. NA's are also ignored.

Usage

prop(x)

prop_col(x)

prop_row(x)

Arguments

x

numeric vector/matrix/data.frame

Value

the same structure as x but with proportions of original values from sum of original values.

Examples

a = c(25, 25, NA)
prop(a)

# data.frame with non-numeric columns
fac = factor(c("a", "b", "c"))
char = c("a", "b", "c")
dat = as.POSIXct("2016-09-27") 
a = sheet(fac, a = c(25, 25, NA), b = c(100, NA, 50), char, dat)

prop(a)
prop_row(a)
prop_col(a)

# the same as result as with 'prop.table'
tbl = table(state.division, state.region)

prop(tbl)
prop_row(tbl)
prop_col(tbl)

expss documentation built on July 26, 2023, 5:23 p.m.