Returns percentage of the occurance of TRUE values in a vector of logical values.

percent(x, min_valid, max_na)

Arguments

x

A vector

min_valid

Minimal number of valid values that is required for calculation. A value between 0 and 1 indicates a proportion of values (e.g., 0.5 = 50 percent of values have to be valid).

max_na

Maximum number of NAs that are allowed before returning NA. A value between 0 and 1 indicates a proportion of values (e.g., 0.5 = 50 percent NAs are allowed).

Value

A percentage

Details

If min_valid is provided, the function will only calculate the percentage if the number of valid (non-NA) values is at least min_valid. If max_na is provided, the function will only calculate the percentage if the number of NAs is at most max_na. If the conditions are not met, NA is returned.

Examples

percent(runif(10000) > 0.50)
#> [1] 49.15