clean_var {explore}R Documentation

Clean variable

Description

Clean variable (replace NA values, set min_val and max_val)

Usage

clean_var(
  data,
  var,
  na = NA,
  min_val = NA,
  max_val = NA,
  max_cat = NA,
  rescale01 = FALSE,
  simplify_text = FALSE,
  name = NA
)

Arguments

data

A dataset

var

Name of variable

na

Value that replaces NA

min_val

All values < min_val are converted to min_val (var numeric or character)

max_val

All values > max_val are converted to max_val (var numeric or character)

max_cat

Maximum number of different factor levels for categorical variable (if more, .OTHER is added)

rescale01

IF TRUE, value is rescaled between 0 and 1 (var must be numeric)

simplify_text

If TRUE, a character variable is simplified (trim, upper, ...)

name

New name of variable (as string)

Value

Dataset

Examples

library(magrittr)
iris %>% clean_var(Sepal.Width, max_val = 3.5, name = "sepal_width") %>% head()
iris %>% clean_var(Sepal.Width, rescale01 = TRUE) %>% head()

[Package explore version 1.3.1 Index]