title: select rows that match condition in several columns
body: <p>I have a dataset with more than 2 million lines and several columns. Some columns are hospital codes, which correspond to all the conditions each patient had during that hospitalisation. I need to perform some summaries for each condition, so I'm trying to create a dataset that will have information about a singular condition of interest.</p>
  
  <p>The codes have 5 digits, but sometimes I want to select codes that begin with three digits (the remaining two digits don't mattter), for instance I want every row that has a code that begin with 401 in all the columns that contains these codes. Small example:</p>
  
  <pre><code>id dx_1 dx_2 dx_3 dx_n
  1  401  
  2  2500 4011
  3  18524
  </code></pre>
  
  <p>I would want id 1 and 2. I've tried something but I get an error and it's slow. Any pointers or suggestions are most welcomed. If anything is unclear I will try to give more information.</p>
  
  <pre><code>final_DB[apply(grep(paste("^", i, sep=""), final_DB[,10:29]), 1, any),]
  </code></pre>
  
  <p><code>i</code> correspond to the number I want so in this case <code>i &lt;- 401</code> and the columns 10 to 29 are all the columns where this code might be.</p>