catProp: Compute Category Proportions

Description Usage Arguments Value Examples

View source: R/utility_functions.R

Description

Given a set of posssible values, computes the proportion of values that actually occurred.

Usage

1
catProp(x, val)

Arguments

x

a vector of values.

val

a character vector with the set of possible values that x can take on.

Value

Returns a vector of proportions that sum to 1.

Examples

1
2
3
4
5
6
7
8
x = rbinom( 100, 1, .7 )
catProp( x, c("0","1") )

# Multiple categories, some categories don't occur
u = runif(100)
x = rep( 'dog', 100 )
x[ u < .33 ] = 'cat'
catProp( x, c("cat","dog","bird" ) )

rettopnivek/utilityf documentation built on March 1, 2021, 7:05 p.m.