fence | R Documentation |
Clip / clamp / or fence, i.e. limit, values to a lower and upper bound.
Similar to raster::clamp()
. This is a wrapper around base::pmin()
and
base::pmax()
; see those for more details.
fence(x, lower = -Inf, upper = Inf, na_rm = FALSE)
x |
Vector of numeric values. |
lower |
Numeric. Lowest value. |
upper |
Numeric. Highest value. |
na_rm |
A logical indicating whether missing values should be removed. |
A numeric vector
https://stackoverflow.com/questions/13868963/clip-values-between-a-minimum-and-maximum-allowed-value-in-r
#### Example 1 --------------------------------
vec <- sample(x = c(1:10),
size = 10,
replace = TRUE)
vec
fence(x = vec,
lower = 4,
upper = 6)
#### Example 2 --------------------------------
library(dplyr)
library(tibble)
df <- tibble::tibble(
vec = vec
)
df %>%
mutate(vec = fence(x = vec,
lower = 4,
upper = 6))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.