0

How can I specify "?" as "ő" in a character vector? (ő is a Hungarian special character) My original vector is:

 [1] "Mez?zombor.dbf"      "Szegi.dbf"           "Szegilong.dbf"       "Szerencs.dbf"       
 [5] "Tarcal.dbf"          "Tiszaladány.dbf"     "Tokaj.dbf"           "Bodrogkeresztúr.dbf"
 [9] "Bodrogkisfalud.dbf"  "Alsóberecki.dbf"     "Bodrogolaszi.dbf"    "Olaszliszka.dbf"    
[13] "Sárazsadány.dbf"     "Sárospatak.dbf"      "Sátoraljaújhely.dbf" "Vajdácska.dbf"      
[17] "Viss.dbf"            "Vámosújfalu.dbf"     "Zalkod.dbf"          "Fels?berecki.dbf"   

I want "Mez?zombor.dbf" shown as "Mezőzombor.dbf". I've tried gsub as:

HHH = gsub("?", "ő", HHH) ## HHH is the vectors name
Chris Ruehlemann
  • 20,321
  • 4
  • 12
  • 34

1 Answers1

0

You will need to escape ?, which is a regex metacharacter, meaning many things, among them optionality (as in x?, which matches xoptionally), 'laziness' as in .*?, which makes the match lazy in the sense that it stops at the first possible match), and to start lookarounds (as in (?<=...), which is a positive lookbehind asserting a condition to the left of the actual match):

 gsub("\\?", "ő", x)
Chris Ruehlemann
  • 20,321
  • 4
  • 12
  • 34