0

Is there an easy way to substitute dashes with dots in every element of character vector in R?

input
c("T-A-B", "C-L1")
output
c("T.A.B", "C.L1")

Was looking for help in stringi package but couldn't find answer. There is stri_substitute function but I don't know how to use this.

Colonel Beauvel
  • 30,423
  • 11
  • 47
  • 87
Marcin
  • 7,834
  • 8
  • 52
  • 99

1 Answers1

6

Base R like this (gsub vectorized thanks to @docendo):

> gsub("-",".",c("T-A-B", "C-L1"))
[1] "T.A.B" "C.L1" 

Or with stringr:

> library(stringr)
> str_replace_all( c("T-A-B", "C-L1"),"-",".")
[1] "T.A.B" "C.L1" 
Colonel Beauvel
  • 30,423
  • 11
  • 47
  • 87