My issue is that I should replace all "." characters in a vector to "-", but I really cant find a working function for that. I tried str_replace and str_replace_all, but failed many times.
The example is:
x<-c("a.b.c", "d.e f")
...
Should return
a-b-c, d-e f
The argument of str_replace_all is a regular expression.
Here's a way how to do it:
library(tidyverse)
x <- c("a.b.c", "d.e f")
# The pattern is always a "regexp" (regular expression)
str_replace_all(x, pattern = "[.]", replacement = "-")
#> [1] "a-b-c" "d-e f"
# or if fixed, then use the stringr::fixed function
str_replace_all(x, pattern = fixed("."), replacement = "-")
#> [1] "a-b-c" "d-e f"