Description Usage Arguments See Also Examples
Trim Whitespace of all Character Columns
1 2 3 4 5 | mutate_all_trimws(
data,
which = c("both", "left", "right"),
whitespace = "[ \t\r\n]"
)
|
data |
A dataframe or tibble. |
which |
a character string specifying whether to remove both
leading and trailing whitespace (default), or only leading
( |
whitespace |
a string specifying a regular expression to match (one character of) “white space”, see Details for alternatives to the default. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | library(tidyverse)
test_data <-
tibble(A = sample(c(NA_integer_, 1:3), size = 10, replace = TRUE),
B = sample(c(NA_integer_, 4:6), size = 10, replace = TRUE),
C = sample(c(" apple ", "banana ", " orange", NA_character_), size = 10, replace = TRUE))
# Mutate all to character
mutate_all_char(test_data)
# Trim whitespace at all character cols
mutate_all_trimws(test_data,
which = "both")
mutate_all_trimws(test_data,
which = "left")
mutate_all_trimws(test_data,
which = "right")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.