Learn R Programming

expss (version 0.11.4)

prop: 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)

Value

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

Arguments

x

numeric vector/matrix/data.frame

Examples

Run this code
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)

Run the code above in your browser using DataLab