Helper function to calculate count and fraction of x values in the lower or upper tail given a threshold.
Usage
h_count_cumulative(
x,
threshold,
lower_tail = TRUE,
include_eq = TRUE,
na.rm = TRUE,
.N_col
)Arguments
- x
(
numeric)
vector of numbers we want to analyze.- threshold
(
number)
a cutoff value as threshold to count values ofx.- lower_tail
(
logical)
whether to count lower tail, default isTRUE.- include_eq
(
logical)
whether to include value equal to thethresholdin count, default isTRUE.- na.rm
(
flag)
whetherNAvalues should be removed fromxprior to analysis.- .N_col
(
count)
denominator for fraction calculation.
Value
A named vector with items:
count: the count of values less than, less or equal to, greater than, or greater or equal to a threshold of user specification.fraction: the fraction of the count.
Examples
set.seed(1, kind = "Mersenne-Twister")
x <- c(sample(1:10, 10), NA)
.N_col <- length(x)
h_count_cumulative(x, 5, .N_col = .N_col)
#> count fraction
#> 5.0000000 0.4545455
h_count_cumulative(x, 5, lower_tail = FALSE, include_eq = FALSE, na.rm = FALSE, .N_col = .N_col)
#> count fraction
#> 6.0000000 0.5454545
h_count_cumulative(x, 0, lower_tail = FALSE, .N_col = .N_col)
#> count fraction
#> 10.0000000 0.9090909
h_count_cumulative(x, 100, lower_tail = FALSE, .N_col = .N_col)
#> count fraction
#> 0 0