Created
March 7, 2019 18:37
-
-
Save paulboardman/9abca3bd0ff20348048379f87f4123b2 to your computer and use it in GitHub Desktop.
use purrr::map_dfc to update all cells in a data.frame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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