title: subsetting R data frame using multiple sets of dates
body: <p>I have the following dataset:</p>
  <pre><code> ID               dates                  d1                  d2                  d3                 d4
   X1 2007-09-09 09:00:00 2007-09-10 09:00:00 2007-09-11 09:00:00                 &lt;NA&gt;               &lt;NA&gt;
   X1 2007-09-10 09:00:00 2007-09-10 09:00:00 2007-09-11 09:00:00                 &lt;NA&gt;               &lt;NA&gt;
   X1 2007-09-11 09:00:00 2007-09-10 09:00:00 2007-09-11 09:00:00                 &lt;NA&gt;               &lt;NA&gt;
   X1 2007-09-13 09:00:00 2007-09-10 09:00:00 2007-09-11 09:00:00                 &lt;NA&gt;               &lt;NA&gt; 
   X2 2007-10-09 09:00:00 2007-10-08 09:00:00 2007-10-10 09:00:00 2007-10-13 09:00:00 2007-10-16 09:00:00
   X2 2007-10-10 09:00:00 2007-10-08 09:00:00 2007-10-10 09:00:00 2007-10-13 09:00:00 2007-10-16 09:00:00
   X2 2007-10-11 09:00:00 2007-10-08 09:00:00 2007-10-10 09:00:00 2007-10-13 09:00:00 2007-10-16 09:00:00
   X2 2007-10-14 09:00:00 2007-10-08 09:00:00 2007-10-10 09:00:00 2007-10-13 09:00:00 2007-10-16 09:00:00
   X2 2007-10-15 09:00:00 2007-10-08 09:00:00 2007-10-10 09:00:00 2007-10-13 09:00:00 2007-10-16 09:00:00
   X2 2007-10-20 09:00:00 2007-10-08 09:00:00 2007-10-10 09:00:00 2007-10-13 09:00:00 2007-10-16 09:00:00
  </code></pre>
  <p>My aim is to subset the data into two datasets, such as one of them has all dates between d1 and d2 AND between d3 and d4, and the other has all remaining dates.</p>
  <p>Here is what the result would look like:</p>
  <p>data1 (dates between d1,d2,d3,d4):</p>
  <pre><code>ID               dates                  d1                  d2                  d3                d4
  X1 2007-09-10 09:00:00 2007-09-10 09:00:00 2007-09-11 09:00:00                &lt;NA&gt;                &lt;NA&gt;
  X1 2007-09-11 09:00:00 2007-09-10 09:00:00 2007-09-11 09:00:00                &lt;NA&gt;                &lt;NA&gt;
  X2 2007-10-09 09:00:00 2007-10-08 09:00:00 2007-10-10 09:00:00 2007-10-13 09:00:00 2007-10-16 09:00:00
  X2 2007-10-10 09:00:00 2007-10-08 09:00:00 2007-10-10 09:00:00 2007-10-13 09:00:00 2007-10-16 09:00:00
  X2 2007-10-14 09:00:00 2007-10-08 09:00:00 2007-10-10 09:00:00 2007-10-13 09:00:00 2007-10-16 09:00:00
  X2 2007-10-15 09:00:00 2007-10-08 09:00:00 2007-10-10 09:00:00 2007-10-13 09:00:00 2007-10-16 09:00:00
  </code></pre>
  <p>data2 (remaining dates):</p>
  <pre><code>ID               dates                  d1                  d2                  d3                  d4
  X1 2007-09-11 09:00:00 2007-09-10 09:00:00 2007-09-11 09:00:00                &lt;NA&gt;                &lt;NA&gt;
  X1 2007-09-13 09:00:00 2007-09-10 09:00:00 2007-09-11 09:00:00                &lt;NA&gt;                &lt;NA&gt;
  X2 2007-10-11 09:00:00 2007-10-08 09:00:00 2007-10-10 09:00:00 2007-10-13 09:00:00 2007-10-16 09:00:00
  X2 2007-10-20 09:00:00 2007-10-08 09:00:00 2007-10-10 09:00:00 2007-10-13 09:00:00 2007-10-16 09:00:00
  </code></pre>
  <p>Would there be a simple way for me to do this?
  Here is the code for my first dataset so you can reproduce it:</p>
  <pre><code>ID&lt;-rep(c(&quot;X1&quot;,&quot;X2&quot;),times=c(4,6))
  dates&lt;-c(&quot;2007-09-09 09:00:00&quot;,&quot;2007-09-10 09:00:00&quot;,&quot;2007-09-11 09:00:00&quot;,&quot;2007-09-13 09:00:00&quot;,&quot;2007-10-09 09:00:00&quot;,&quot;2007-10-10 09:00:00&quot;,&quot;2007-10-11 09:00:00&quot;,&quot;2007-10-14 09:00:00&quot;, &quot;2007-10-15 09:00:00&quot;,&quot;2007-10-20 09:00:00&quot;)
  d1&lt;-rep(c(&quot;2007-09-10 09:00:00&quot;,&quot;2007-10-08 09:00:00&quot;),times=c(4,6))
  d2&lt;-rep(c(&quot;2007-09-11 09:00:00&quot;,&quot;2007-10-10 09:00:00&quot;),times=c(4,6))
  d3&lt;-rep(c(NA,&quot;2007-10-13 09:00:00&quot;),times=c(4,6))
  d4&lt;-rep(c(NA,&quot;2007-10-16 09:00:00&quot;),times=c(4,6))
  data&lt;-data.frame(ID,dates,d1,d2,d3,d4)
  </code></pre>