title: gsub apply combination in R
body: <p>I am trying to use gsub on every column of a dataframe to remove some characters, I have tried using apply to do this without success:</p>
  
  <pre><code>data&lt;-apply(data,2, function(x) gsub("£","",data[x]))
  </code></pre>
  
  <p>returns error </p>
  
  <pre><code>Error in `[.data.frame`(data, x) : undefined columns selected
  </code></pre>
  
  <p>I know it works if I do </p>
  
  <pre><code>for(i in 1: length(data)){data[,i]&lt;-gsub("£","",data[,i]) }
  </code></pre>
  
  <p>But why doesn't the apply call work? </p>