Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement