title: Character replacement with gsub not working inside a function
body: <p>I'm trying to replace some unexpected characters in a data frame in R. According to <a href="https://stackoverflow.com/questions/15253954/replace-multiple-arguments-with-gsub">Replace multiple arguments with gsub</a>, gsub function is supposed to work properly in this cases, so I tried that way.</p>
  
  <p>The values I have in the first column of the data frame are the following:</p>
  
  <pre><code>La FlÃ¨che Wallonne
  LiÃ¨ge - Bastogne - LiÃ¨ge
  Tour de Romandie
  Giro dÂ´Italia
  CritÃ©rium du DauphinÃ©
  </code></pre>
  
  <p>And the code's been implemented as follows:</p>
  
  <pre><code>callChangeCharacters &lt;- function(results){
  for(i in 1:nrow(results)){
      race &lt;- results[i,1]
      race &lt;- gsub("Ã©","e",race)
      race &lt;- gsub("Ã¢","a",race)
      race &lt;- gsub("Ã³","o",race)
      race &lt;- gsub("Å¾","z",race)
      race &lt;- gsub("Ãº","u",race)
      race &lt;- gsub("Ã¸","o",race)
      race &lt;- gsub("Å›","s",race)
      race &lt;- gsub("Å‚","l",race)
      race &lt;- gsub("Ã¤‚","a",race)
      race &lt;- gsub("Ã¨","e",race)
      race &lt;- gsub("Ã","a",race)
      race &lt;- gsub("Å","s",race)
      race &lt;- gsub("Ä","c",race)
      race &lt;- gsub("Â´","'",race)
      results[i,1] &lt;- race
  }
  return(results)
  }
  </code></pre>
  
  <p>If I run the code which is inside the for loop, I success to get the expected result:</p>
  
  <pre><code>La Fleche Wallonne
  Liege - Bastogne - Liege
  Tour de Romandie
  Giro d'Italia
  Criterium du Dauphine
  </code></pre>
  
  <p>However, if I call the function, the result isn't the same, and the unwanted characters aren't corrected:</p>
  
  <pre><code>&gt; correctedDF &lt;- callChangeCharacters(results)
  &gt; correctedDF
                                          V1
  La FlÃ¨che Wallonne
  LiÃ¨ge - Bastogne - LiÃ¨ge
  Tour de Romandie
  Giro dÂ´Italia
  CritÃ©rium du DauphinÃ©
  </code></pre>
  
  <p>The output of the result I get is the following (this version of results is longer but the problem is the same):</p>
  
  <pre><code>&gt; dput(results)
  structure(list(V1 = c("Santos Tour Down Under", "Paris - Nice", 
  "Tirreno-Adriatico", "Milano-Sanremo", "Volta Ciclista a Catalunya", 
  "E3 Prijs Vlaanderen - Harelbeke", "Gent - Wevelgem", "Ronde van Vlaanderen / Tour des Flandres", 
  "Vuelta Ciclista al Pais Vasco", "Paris - Roubaix", "Amstel Gold Race", 
  "La FlÃ¨che Wallonne", "LiÃ¨ge - Bastogne - LiÃ¨ge", "Tour de Romandie", 
  "Giro dÂ´Italia", "CritÃ©rium du DauphinÃ©", "Tour de Suisse", 
  "Tour de France", "Tour de Pologne", NA, "Clasica Ciclista San Sebastian", 
  "Eneco Tour", "Vuelta a EspaÃ±a", "Vattenfall Cyclassics", "GP Ouest France - Plouay", 
  "Grand Prix Cycliste de QuÃ©bec", "Grand Prix Cycliste de MontrÃ©al", 
  "Il Lombardia", "Tour of Beijing")), .Names = "V1", row.names = c(1L, 
  1686L, 4601L, 6743L, 6943L, 9274L, 9473L, 9673L, 9880L, 11581L, 
  11779L, 11978L, 12168L, 12367L, 14264L, 21957L, 24734L, 27727L, 
  35542L, 37354L, 37470L, 37627L, 39885L, 47277L, 47441L, 47624L, 
  47788L, 47952L, 48147L), class = "data.frame")
  </code></pre>
  
  <p>Any idea of why it doesn't work inside the function?</p>
  
  <p>Thanks in advance.</p>