is_perc: Verify that input is a percentage (numeric value from 0 to...

View source: R/comp_util.R

is_percR Documentation

Verify that input is a percentage (numeric value from 0 to 100).

Description

is_perc is a function that checks whether its single argument perc is a percentage (proportion, i.e., a numeric value in the range from 0 to 100).

Usage

is_perc(perc)

Arguments

perc

A single (typically numeric) argument.

Value

A Boolean value: TRUE if perc is a percentage (proportion), otherwise FALSE.

See Also

num contains basic numeric variables; init_num initializes basic numeric variables; prob contains current probability information; comp_prob computes current probability information; freq contains current frequency information; comp_freq computes current frequency information; is_valid_prob_set verifies the validity of probability inputs; as_pc displays a probability as a percentage; as_pb displays a percentage as probability.

Other verification functions: is_complement(), is_extreme_prob_set(), is_freq(), is_integer(), is_matrix(), is_prob(), is_suff_prob_set(), is_valid_prob_pair(), is_valid_prob_set(), is_valid_prob_triple()

Examples

# ways to succeed:
is_perc(2)    # => TRUE, but does NOT return the percentage 2.
is_perc(1/2)  # => TRUE, but does NOT return the percentage 0.5.

## note:
# pc_sq <- seq(0, 100, by = 10)
# is_perc(pc_sq)       # => TRUE (for vector)

## ways to fail:
# is_perc(NA)          # => FALSE + warning (NA values)
# is_perc(NaN)         # => FALSE + warning (NaN values)
# is_perc("Bernoulli") # => FALSE + warning (non-numeric values)
# is_perc(101)         # => FALSE + warning (beyond range)


riskyr documentation built on Aug. 15, 2022, 9:09 a.m.