title: Subset strings in R
body: <p>One of the strings in my vector (df$location1) is the following:</p>
  
  <pre><code>Potomac, MD 20854\n(39.038266, -77.203413)
  </code></pre>
  
  <p>Rest of the data in the vector follow same pattern. I want to separate each component of the string into a separate data element and put it in new columns like: df$city, df$state, etc. </p>
  
  <p>So far I have been able to isolate the lat. long. data into a separate column by doing the following:</p>
  
  <pre><code>df$lat.long &lt;- gsub('.*\\\n\\\((.*)\\\)','\\\1',df$location1)
  </code></pre>
  
  <p>I was able to make it work by looking at other codes online but I don't fully understand it. I understand the regex pattern but don't understand the "\\1" part. Since I don't understand it in full I have been unable to use it to subset other parts of this same string. </p>
  
  <ul>
  <li>What's the best way to subset data like this? </li>
  <li>Is using regex a good way to do this? What other ways should I be looking into?</li>
  </ul>
  
  <p>I have looked into splitting the string after a comma, subset using regex, using scan() function and to many other variations. Now I am all confused. Thx</p>