title: Use R to extract numeric values from string in a column
body: <p>I have a table with the following column structure :</p>
  <pre><code>Name                                                Type
  Urgent Care (Revenue Code: 0456)                    Per Case
  IV Therapy (Revenue Codes 0260, 0269)               Per Visit
  Oncology Treatment (Revenue Codes: 0280, 0289)      Per Visit
  </code></pre>
  <p>and I want to extract the numeric revenue codes from the names column so the table would look like :</p>
  <pre><code>Name                     Rev Code      Type
  Urgent Care              0456          Per Case
  IV Therapy               0260, 0269    Per Visit
  Oncology Treatment       0280, 0289    Per Visit
  </code></pre>
  <p>the original data is inconsistent in the Name column as the word &quot;Code&quot; is followed by a &quot;;&quot; , blank space, &quot;-&quot; etc.  So I was trying to use regular expression to search for the first number and then split the column there.</p>
  <p>I have tried using regex to search for the first digit and separate() from the tidyr package :</p>
  <pre><code>library(tidyr)
  separate(mydata, Name, into = c(&quot;Name&quot;, &quot;Rev Code&quot;), sep = &quot;[[:digit:]]&quot;)
  </code></pre>
  <p>which splits the column at the right location but the column &quot;Rev Code&quot; ends up blank?
  I'm relatively new to R and would definitely appreciate any help!</p>
  <h3>Data:</h3>
  <pre><code>structure(list(
  Name = c(&quot;Urgent Care (Revenue Code: 0456)&quot;, &quot;IV Therapy (Revenue Codes 0260, 0269)&quot;, 
  &quot;Oncology Treatment (Revenue Codes: 0280, 0289)&quot;), 
  Type = c(&quot;Per Case&quot;, &quot;Per Visit&quot;, &quot;Per Visit&quot;)), 
  .Names = c(&quot;Name&quot;, &quot;Type&quot;), row.names = 1:3, class = &quot;data.frame&quot;)
  </code></pre>