This function "cleans" values of a character vector or levels of a factor by removing space and punctuation characters.

tidy_values(x, ...)

clean_values(x, ...)

Arguments

x

A vector or data frame.

...

Optional, unquoted names of variables that should be selected for further processing. Required, if x is a data frame (and no vector) and only selected variables from x should be processed. You may also use functions like : or tidyselect's select-helpers. See 'Examples' or package-vignette.

Value

x, with "cleaned" values or levels.

Examples

f1 <- sprintf("Char %s", sample(LETTERS[1:5], size = 10, replace = TRUE))
f2 <- as.factor(sprintf("F / %s", sample(letters[1:5], size = 10, replace = TRUE)))
f3 <- sample(1:5, size = 10, replace = TRUE)

x <- data.frame(f1, f2, f3, stringsAsFactors = FALSE)

clean_values(f1)
#>  [1] "Char_E" "Char_A" "Char_B" "Char_B" "Char_A" "Char_C" "Char_D" "Char_B"
#>  [9] "Char_B" "Char_C"
clean_values(f2)
#>  [1] F_e F_c F_e F_c F_d F_e F_c F_b F_a F_d
#> Levels: F_a F_b F_c F_d F_e
clean_values(x)
#> # A tibble: 10 × 3
#>    f1     f2       f3
#>    <chr>  <fct> <int>
#>  1 Char_E F_e       4
#>  2 Char_A F_c       3
#>  3 Char_B F_e       4
#>  4 Char_B F_c       1
#>  5 Char_A F_d       5
#>  6 Char_C F_e       5
#>  7 Char_D F_c       1
#>  8 Char_B F_b       4
#>  9 Char_B F_a       2
#> 10 Char_C F_d       3