title: subseting with grep in data.table - unpredicatble
body: <p>Why is "grep" causing problems in the below data.table calls.</p>
  
  <pre><code>set.seed(45)
  dt &lt;- data.table(
      col1 = sample(letters[1:2],10, replace=TRUE), 
      col2=sample(letters[1:5], 10, replace=TRUE),
      col3=runif(10,1,5))
  </code></pre>
  
  <p>Subsetting like this, works:</p>
  
  <pre><code>dt[col1=="b" &amp; col2=="b",] # Works
      col1 col2     col3
  1:    b    b    1.5166
  </code></pre>
  
  <p>But this throws a warning and returns wrong data (or no warning and wrong data)</p>
  
  <pre><code>dt[grep("b", col1) &amp; col2=="b",] # does not
  # with seed = 42
  &gt; Warning message: In grep("b", col1) &amp; col2 == "b" :   longer object
  &gt; length is not a multiple of shorter object length
  # with seed = 45
     col1 col2     col3
  1:    b    b 1.516600
  2:    a    b 3.342007
  3:    a    b 1.865772
  </code></pre>
  
  <p>I can avoid this confusion by tying the subsets together:</p>
  
  <pre><code>dt[grep("b", col1),][col2=="b",]
  </code></pre>
  
  <p>But that is not very elegant.</p>
  
  <p>ps. I guess the problem is different than <a href="https://stackoverflow.com/questions/19993311/r-losing-data-during-subsetting-data-table">here</a></p>