proportion: Proportions

Description Usage Arguments Details Examples

View source: R/proportions.R

Description

Calculates a proportion from a vector or data frame/matrix.

Usage

1
2
3
4
5
6
7
8
9
proportion(x, ...)

prop_tapply(x, ...)

## Default S3 method:
prop_tapply(x, ...)

## S3 method for class 'data.frame'
prop_tapply(x, col, ...)

Arguments

x

A data.frame or a vector.

...

Additional arguments to be passed to methods.

Details

tapply(x, x, length) / length(x) can be speedier for smaller data sets and groups but slows down with more data or a greater number of groups.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
proportion(iris, "Species")
proportion(iris$Species)

## Not run: 
 tapply = prop_tapply(iris, "Sepal.Length"),
 proportion = proportion(iris, "Sepal.Length"),
 times = 100
)

x <- dplyr::sample_n(iris, 1e6, TRUE)
microbenchmark::microbenchmark(
 tapply = prop_tapply(x, "Sepal.Length"),
 proportion = proportion(x, "Sepal.Length"),
 times = 10
)
## End(Not run)

jmbarbone/qpm documentation built on July 25, 2020, 10:41 p.m.