title: Filter rows based on variables "beginning with" strings specified by vector
body: <p>I'm trying to filter a patient database based on specific ICD9 (diagnosis) codes. I would like to use a vector indicating the first 3 strings of the ICD9 codes.</p>
  
  <p>The example database contains 3 character variables for IC9 codes for each patient visit (var1 to var3).</p>
  
  <p>Below is an example of the data</p>
  
  <pre><code>patient&lt;-c("a","b","c")
  var1&lt;-c("8661", "865","8651")
  var2&lt;-c("8651","8674","2866")
  var3&lt;-c("2430","3456","9089")
  
  observations&lt;-data_frame(patient,var1,var2,var3)
  
     patient  var1  var2  var3
  1       a  8661  8651  2430
  2       b  865   8674  3456
  3       c  8651  2866  9089
  
  #diagnosis of interest: all beginning with "866" and "867"
  dx&lt;-c("866","867")
  
  filtered_data&lt;- filter(observations, var1 %like% dx | var2 %like% dx | var3 %like% dx)  
  </code></pre>
  
  <p>I have tried several approaches including the grep and the %like% functions as you can see above but I haven’t been able to get it working for my case. I would appreciate any help you can provide. </p>
  
  <p>Happy thanksgivings</p>
  
  <p>Albit</p>