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, ...)
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.
x
, with "cleaned" values or levels.
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_B" "Char_C" "Char_C" "Char_B" "Char_D" "Char_A" "Char_D" "Char_E"
#> [9] "Char_B" "Char_A"
clean_values(f2)
#> [1] F_c F_c F_d F_b F_d F_d F_a F_b F_c F_c
#> Levels: F_a F_b F_c F_d
clean_values(x)
#> # A tibble: 10 × 3
#> f1 f2 f3
#> <chr> <fct> <int>
#> 1 Char_B F_c 3
#> 2 Char_C F_c 1
#> 3 Char_C F_d 2
#> 4 Char_B F_b 4
#> 5 Char_D F_d 5
#> 6 Char_A F_d 2
#> 7 Char_D F_a 5
#> 8 Char_E F_b 1
#> 9 Char_B F_c 2
#> 10 Char_A F_c 5