Created
April 23, 2024 12:58
-
-
Save PietrH/31953a485595cdf2ebb3fb846d438ffd to your computer and use it in GitHub Desktop.
paste0() but drop NA instead
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
str_replace_na <- function(string, replacement = ""){ | |
string[is.na(string)] <- replacement | |
return(string) | |
} | |
c("a", NA, "c") |> str_replace_na(replacement = "") |> paste0(collapse = " ") | |
#> [1] "a c" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment