title: Remove special characters from entire dataframe in R
body: <p><strong>Question:</strong> </p>
  
  <p>How can you use R to remove all special characters from a dataframe, quickly and efficiently? </p>
  
  <p><strong>Progress:</strong></p>
  
  <p>This SO <a href="https://stackoverflow.com/questions/21641522/how-to-remove-specific-special-characters-in-r/21641569">post</a> details how to remove special characters. I can apply the gsub function to single columns (images 1 and 2), but not the entire dataframe.</p>
  
  <p><strong>Problem:</strong></p>
  
  <p>My dataframe consists of 100+ columns of integers, string, etc. When I try to run the gsub on the dataframe, it doesn't return the output I desire. Instead, I get what's shown in image 3.</p>
  
  <pre><code>df &lt;- read.csv("C:/test.csv")
  dfa &lt;- gsub("[[:punct:]]", "", df$a) #this works on a single column
  dfb &lt;- gsub("[[:punct:]]", "", df$b) #this works on a single column
  df_all &lt;- gsub("[[:punct:]]", "", df) #this does not work on the entire df
  View(df_all)
  </code></pre>
  
  <p><strong>df</strong> - This is the original dataframe:</p>
  
  <p><a href="https://i.stack.imgur.com/z3EaQ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/z3EaQ.png" alt="Original dataframe"></a></p>
  
  <p><strong>dfa</strong> - This is gsub applied to column b. Good!</p>
  
  <p><a href="https://i.stack.imgur.com/EE1fV.png" rel="noreferrer"><img src="https://i.stack.imgur.com/EE1fV.png" alt="gsub applied to column b"></a></p>
  
  <p><strong>df_all</strong> - This is gsub applied to the entire dataframe. Bad!</p>
  
  <p><a href="https://i.stack.imgur.com/Ciec5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Ciec5.png" alt="gsub applied to entire dataframe"></a></p>
  
  <p><strong>Summary:</strong></p>
  
  <p>Is there a way to gsub an entire dataframe? Else, should an apply function be used instead?</p>