View source: R/is_almost_constant.R
| is_almost_constant | R Documentation |
Check if a vector contains (almost) the same value in the majority of its
elements. The function returns TRUE if the proportion of the most frequent
value in x is greater than or equal to the specified threshold.
is_almost_constant(x, threshold = 1, na_rm = FALSE)
x |
A vector to be tested. |
threshold |
A numeric scalar in the interval |
na_rm |
Logical; if |
This is useful for detecting low-variability or degenerate variables, which may be uninformative in modeling or analysis.
A logical scalar. Returns TRUE in the following cases:
x is empty or has length one.
x contains only NA values.
The proportion of the most frequent value in x is greater than or
equal to threshold.
Otherwise, returns FALSE.
Michal Burda
remove_almost_constant(), unique(), table()
is_almost_constant(1)
is_almost_constant(1:10)
is_almost_constant(c(NA, NA, NA), na_rm = TRUE)
is_almost_constant(c(NA, NA, NA), na_rm = FALSE)
is_almost_constant(c(NA, NA, NA, 1, 2), threshold = 0.5, na_rm = FALSE)
is_almost_constant(c(NA, NA, NA, 1, 2), threshold = 0.5, na_rm = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.