Created
October 2, 2019 16:23
-
-
Save geotheory/71c93412e8091155a5ea3f5f8eed305a to your computer and use it in GitHub Desktop.
This file contains 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
require(tidyverse) | |
unite2 = function(x, col, ..., sep = '_', remove = TRUE){ | |
unite(x, 'tmpcol', ..., sep = '∞-∞', remove = remove) %>% | |
mutate(tmpcol = tmpcol %>% str_remove_all('∞-∞NA(?=∞|$)') %>% str_replace_all('∞-∞', sep)) %>% | |
rename(!!col := tmpcol) | |
} | |
x = tibble(x=c('the','a','my'), y=c('brown','cat',NA),z=c('dog',NA,'bird')) | |
unite2(x, col = 'xzy', c('x','y','z'), sep=' ') | |
#> # A tibble: 3 x 1 | |
#> xzy | |
#> <chr> | |
#> 1 the brown dog | |
#> 2 a cat | |
#> 3 my bird |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment