proportion_true | R Documentation |
Given a suitable input (logical vector/matrix/array, numeric/integer vector/matrix/array), find the proportion of true values. Automatically removes NAs.
proportion_true(x)
x |
(numeric vector) A vector of values. |
#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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.