tidy_values: Clean values of character vectors.

Description Usage Arguments Value Examples

View source: R/tidy_values.R

Description

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

Usage

1
2
3

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

1
2
3
4
5
6
7
8
9
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)
clean_values(f2)
clean_values(x)

Example output

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

sjmisc documentation built on Dec. 11, 2021, 9:34 a.m.