Skip to content

Instantly share code, notes, and snippets.

@paulboardman
Created March 7, 2019 18:37
Show Gist options
  • Save paulboardman/9abca3bd0ff20348048379f87f4123b2 to your computer and use it in GitHub Desktop.
Save paulboardman/9abca3bd0ff20348048379f87f4123b2 to your computer and use it in GitHub Desktop.
use purrr::map_dfc to update all cells in a data.frame
# replace all insances of '.' in all columns without changing anything else.
dt <- data.frame(
a=sample(LETTERS, 10),
b=sample(c('.', 1, 2, 3), 10, replace=T),
c=sample(c('.', 'rick', 'morty', 'summer'), 10, replace=T))
# print the data.frame
dt
# use purrr::map_dfc to loop through the columns of the data.frame
dt %>%
purrr::map_dfc(
function(x) str_replace(x, '^\\.$', replacement=NA_character_))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment