Why does gsub/sub not work to replace ".."?

Cory

When I call rownames on my df I get something like this:

"Saint.Petersburg..Russia"           "Istanbul..Turkey" 

This what I coded

gsub("..", " ", rownames(df))

This is what was returned

 [1] "            "      "        "          "   

What I expected was

"Saint.Petersburg Russia"           "Istanbul Turkey"  

Does anyone know what is going wrong here?

akrun

We can use fixed = TRUE as . can match any character in the default regex mode if it is not escaped (\\.) or placed inside square brackets ([.]) or the faster option is fixed = TRUE

gsub("..", " ", rownames(df), fixed = TRUE)
#[1] "Saint.Petersburg Russia" "Istanbul Turkey"   

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related