proportion_true: Proportion true

View source: R/simple_math.R

proportion_trueR Documentation

Proportion true

Description

Given a suitable input (logical vector/matrix/array, numeric/integer vector/matrix/array), find the proportion of true values. Automatically removes NAs.

Usage

proportion_true(x)

Arguments

x

(numeric vector) A vector of values.

Examples

#sample some logical data
x = sample(c(T, F), size = 100, replace = T)
proportion_true(x)
#sample some logical data with NAs
x = sample(c(T, F, NA), size = 100, replace = T)
proportion_true(x) #no errors or NA output
#converts input to logical if possible
x = sample(c(1, 0), size = 100, replace = T)
proportion_true(x)
#throws errors if it gets a nonsensical input
"str" %>% proportion_true() #character
data.frame() %>% proportion_true() #data.frame
list() %>% proportion_true()

Deleetdk/kirkegaard documentation built on April 22, 2024, 5:22 p.m.