clean_character_columns | R Documentation |
Removes leading and trailing whitespace from all character columns
in a data frame using trimws
.
clean_character_columns(df)
df |
A data frame or tibble containing character columns to be cleaned |
The function uses dplyr::across
to apply trimws
to all columns
that are of type character. The original data frame structure is preserved,
only the content of character columns is modified.
A data frame of the same structure as the input, but with whitespace removed from all character columns
df <- data.frame(
name = c(" John ", "Jane ", " Bob"),
age = c(25, 30, 35),
city = c("New York ", " London", " Paris ")
)
clean_df <- clean_character_columns(df)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.