1

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?

Cory
  • 13
  • 3
  • 1
    `"."` is a special character in regex that matches any character. To match a literal period, you need to escape it – camille Jan 25 '20 at 00:20

1 Answers1

0

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"   
akrun
  • 874,273
  • 37
  • 540
  • 662