ra_truncate | R Documentation |
Truncates a vector of numeric variables to a specific range. Different methods of truncating the distribution are provided. 'ignore' will ignore the values outside the provided range. 'sub' will substitute the values outside the provided range with the min and max. 'resample' will bootstrap resample the values outside the distribution from the input values
ra_truncate(x, range, method = "ignore")
x |
vector of values to truncate |
range |
range of values to truncate at |
method |
method for the truncation. default is 'ignore', which will ignore all the values out of the range. 'sub' will substitute the values out of the range for the min and max values. 'resample' will resample the values of out range from the values inside the range. |
A vector of numeric values with the truncated values
# sample from a pert distribution
x <- ra_sample('pert(60, 80, 120)', n = 1000)
# method, ignore: ignore values out of bounds
ra_truncate(x = x, range = c(10, 90)) %>%
ra_plot_dist(main = 'Ignore')
# method substitute: substitute values out of bounds for min max provided
ra_truncate(x = x, range = c(10, 90), method = 'sub') %>%
ra_plot_dist(main = 'Substitution')
# Method resample: Resample values out of bounds for values inside bounds
ra_truncate(x = x, range = c(10, 90), method = 'resample') %>%
ra_plot_dist(main = 'Resample')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.