powered by
Clean variable (replace NA values, set min_val and max_val)
clean_var( data, var, na = NA, min_val = NA, max_val = NA, max_cat = NA, rescale01 = FALSE, simplify_text = FALSE, name = NA )
Dataset
A dataset
Name of variable
Value that replaces NA
All values < min_val are converted to min_val (var numeric or character)
All values > max_val are converted to max_val (var numeric or character)
Maximum number of different factor levels for categorical variable (if more, .OTHER is added)
IF TRUE, value is rescaled between 0 and 1 (var must be numeric)
If TRUE, a character variable is simplified (trim, upper, ...)
New name of variable (as string)
library(magrittr) iris %>% clean_var(Sepal.Width, max_val = 3.5, name = "sepal_width") %>% head() iris %>% clean_var(Sepal.Width, rescale01 = TRUE) %>% head()
Run the code above in your browser using DataLab