Replace. in R

How can I replace .. using.

I tried something like:

names(dataset) <- gsub("[/./.]",".",names(dataset)) 

But this does not work, as I had hoped.

+6
source share
2 answers

Try adding fixed = T

 R> c <- "v.." [1] "v.." R> gsub("..", '.', c, fixed = T) [1] "v." 
+12
source

I think you have slashes in the wrong direction, and you need to double them:

 gsub("\\.\\.",".",names(dataset)) 

Fixed display of comments.

+5
source

Source: https://habr.com/ru/post/902976/


All Articles