title: How to use Sub Function in R
body: <p>I am reading a csv file "<code>dopers</code>" in R.</p>
  
  <pre><code>dopers &lt;- read.csv(file="generalDoping_alldata2.csv", head=TRUE,sep=",")
  </code></pre>
  
  <p>After reading the file, I have to do some data cleanup. For instance in the <code>country</code> column if it says </p>
  
  <p>"United States" or "United State"</p>
  
  <p>I would like to replace it with <code>"USA"</code></p>
  
  <p>I want to make sure that, if the word is <code>"  United States    "</code> or <code>"United   State   "</code>, even them my code should work. What I want to say is that even if there is any character before and after <code>"United States"</code> it is replaced with <code>"USA"</code>. I understand we can use <code>sub()</code> function for that purpose. I was looking online and found this, however I do not understand what <code>"^" "&amp;" "*" "."</code> does. Can someone please explain.</p>
  
  <pre><code>dopers$Country = sub("^UNITED STATES.*$", "USA", dopers$Country)
  </code></pre>