title: Use a regular expression extract substring from data frame columns in R
body: <p>I am fairly new to R so please go easy on me if this is a stupid question.</p>
  
  <p>I have a dataframe called <code>foo</code>:</p>
  
  <pre><code>&lt; head(foo)
    Old.Clone.Name New.Clone.Name                                  File
  1         A          Aa           A_mask_MF_final_IS2_SAEE7-1_02.nrrd
  2         B          Bb   B_mask_MF_final_IS2ViaIS2h_SADQ15-1_02.nrrd
  3         C          Cc   C_mask_MF_final_IS2ViaIS2h_SAEC16-1_02.nrrd
  4         D          Dd    D_mask_MF_final_IS2ViaIS2h_SAEJ6-1_02.nrrd
  5         E          Ee           F_mask_MF_final_IS2_SAED9-1_02.nrrd
  6         F          Ff    F_mask_MF_final_IS2ViaIS2h_SAGP3-1_02.nrrd
  </code></pre>
  
  <p>I want to extract codes from the <code>File</code> column that match the regular expression <code>(S[A-Z]{3}[0-9]{1,2}-[0-9]_02)</code>, to give me:</p>
  
  <pre><code>SAEE7-1_02
  SADQ15-1_02
  SAEC16-1_02
  SAEJ6-1_02
  SAED9-1_02
  SAGP3-1_02
  </code></pre>
  
  <p>I then want to use these codes to search another directory for other files that contain the same code.</p>
  
  <p>I fail, however, at the first hurdle and cannot extract the codes from that column of the data frame. </p>
  
  <p>I have tried:</p>
  
  <pre><code>library('stringr')
  str_extract(foo[3],regex("(S[A-Z]{3}[0-9]{1,2}-[0-9]_02)", ignore_case = TRUE))
  </code></pre>
  
  <p>but this just returns <code>[1] NA</code>.</p>
  
  <p>Am I simply missing something obvious? I look forward to cracking this with a bit of help from the community.</p>