Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replace .. with . in R

Tags:

regex

r

How can I replace .. with .

I tried something like:

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

But it doesn't work as I hoped.

like image 514
darckeen Avatar asked Dec 02 '11 23:12

darckeen


Video Answer


2 Answers

Try adding fixed = T

R> c <- "v.."
[1] "v.."
R> gsub("..", '.', c, fixed = T)
[1] "v."
like image 155
Stedy Avatar answered Sep 19 '22 19:09

Stedy


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

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

Fixed to reflect comments.

like image 32
joran Avatar answered Sep 18 '22 19:09

joran