percent {rapportools}R Documentation

Percent

Description

Calculates percentage of cases for provided variable and criteria specified in subset argument. Function accepts numeric, factor and logical variables for x parameter. If numeric and/or factor is provided, subsetting can be achieved via subset argument. Depending on value of na.rm argument, either valid (na.rm = TRUE) or all cases (na.rm = FALSE) are taken into account. By passing logical variable to x, a sum of (TRUE) elements is calculated instead, and valid percents are used (NA are excluded).

Usage

percent(x, subset = NULL, na.rm = TRUE, pct = FALSE, ...)

Arguments

x

a numeric variable to be summarised

subset

an expression that evaluates to logical vector (defaults to NULL)

na.rm

should missing values be

pct

print percent string too?

...

additional arguments for pct function

Value

a numeric or string depending on the value of pct

Examples

## Not run: 
set.seed(0)
x <- sample(5, 100, replace = TRUE)
percent(x > 2)

## End(Not run)

[Package rapportools version 1.1 Index]