Skip to content

Instantly share code, notes, and snippets.

@damianooldoni
Last active August 7, 2018 13:38
Show Gist options
  • Save damianooldoni/5da5ea4685a82bcedcc59d5e8384d83b to your computer and use it in GitHub Desktop.
Save damianooldoni/5da5ea4685a82bcedcc59d5e8384d83b to your computer and use it in GitHub Desktop.
Removes whitespace from start, end and repeated whitespaces inside all dataframe.
library(dplyr)
library(stringr)
df <- data.frame(a = c(" aZe aze s", "wxc s aze "),
b = c(" 12 12 ", "34e e4 "),
stringsAsFactors = FALSE)
df <- df %>%
rowwise() %>%
mutate_all(funs(str_squish(.))) %>%
ungroup()
df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment