Delete all points with gsub

2

I want to know how to correct the code to delete a character (period) in an identity number variable (eg: "2.564.752" convert to "2564752" ).

Instead of deleting just that character, it ends up deleting all my variable, would you have any suggestions?

becal_cobertura = gsub('.', '', becal_cobertura)
    
asked by Jazz Duarte 01.02.2018 в 15:00
source

1 answer

1

What happens is that the character dot / dot . has a special meaning in regular expressions, it's like a wildcard, it represents any character. To be able to literally search for . you can escape using \ in the following way:

gsub('\.', '', '2.564.752')
[1] "2564752"

Note: In R to indicate the backslash, it must be written double \ .

Or Eventually

gsub('[.]', '', '2.564.752')
[1] "2564752"

And finally, but without using regular expressions, you can do:

gsub('.', '', '2.564.752', fixed = T)
[1] "2564752"
    
answered by 01.02.2018 / 15:10
source