Learn R Programming

checkthat (version 0.1.0)

prop: Calculate Proportion of TRUE Values in a Logical Vector

Description

This function calculates the proportion of TRUE values in a logical vector.

Usage

prop(logical_vec, na.rm = FALSE)

Value

The proportion of TRUE values in the logical vector.

Arguments

logical_vec

A logical vector.

na.rm

Logical. Should missing values be removed before calculation? Behaves similar to base::mean, removing missing values from both the numerator and denominator of the proportion calculation.

Examples

Run this code
prop(c(TRUE, TRUE, FALSE, TRUE)) # Returns 0.75
prop(c(TRUE, FALSE, TRUE, FALSE, NA), na.rm = TRUE) # Returns 0.5

Run the code above in your browser using DataLab