Learn R Programming

rapport (version 0.51)

rp.percent: 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

rp.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

Run this code
set.seed(0)
x <- sample(5, 100, replace = TRUE)
rp.percent(x > 2)

Run the code above in your browser using DataLab