title: Trouble with subsetting with multiple conditions in R
body: <p>I am trying to get to the bottom of why I can't subset in R.</p>
  
  <p>My dataset, Rdataset, has 3 columns: Epoch, Distance and BaselineVectorID.
  What I want to do is subset the Distance based upon multiple conditions of Epoch.  I looked at multiple Q&amp;A on StackOverflow and have tried many of the responses over my dataset but none work.  Here is the background:</p>
  
  <p>First, with Epoch ranging from 2007-11-15 to 2011-03-30 I set </p>
  
  <pre><code>StartDate &lt;- "2008-01-01"
  as.numeric(as.Date(StartDate)); StartDate
  </code></pre>
  
  <p>Then I quantify the duration of time window</p>
  
  <pre><code>ShortTermDuration &lt;-  30
  LongTermDuration  &lt;- 365
  </code></pre>
  
  <p>Then I define the time window,</p>
  
  <pre><code>MonthAhead  &lt;- as.Date(StartDate) + ShortTermDuration;  MonthAhead
  MonthBehind &lt;- as.Date(StartDate) - ShortTermDuration; MonthBehind
  </code></pre>
  
  <p>Then I want to define the smaller dataset by subsetting and have tried each of the different methods below with the associated result:</p>
  
  <p>1.</p>
  
  <pre><code>Rdataset[Rdataset$Epoch &gt;= "2008-01-01" &amp; Rdataset$Epoch &lt; "2008-02-01"]
  </code></pre>
  
  <p>Result: </p>
  
  <pre><code>data frame with 0 columns and 703 rows
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>ShortTermDataset &lt;- subset(Rdataset, Epoch&gt;=MonthBehind &amp; Epoch&lt;=MonthAhead)
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>Warning messages:
  1: In eval(expr, envir, enclos) :
  Incompatible methods ("Ops.POSIXt", "Ops.Date") for "&gt;="
  2: In eval(expr, envir, enclos) :
  Incompatible methods ("Ops.POSIXt", "Ops.Date") for "&lt;="
  [1] Epoch            Distance         BaselineVectorID
  &lt;0 rows&gt; (or 0-length row.names)
  </code></pre>
  
  <p>3.</p>
  
  <pre><code>ShortTerm.df &lt;- Rdataset[Epoch&gt;=MonthBehind &amp; Epoch&lt;MonthAhead, ]
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>Error in `[.data.frame`(Rdataset, Epoch &gt;= MonthBehind &amp; Epoch &lt; MonthAhead,  : 
  object 'Epoch' not found
  </code></pre>
  
  <p>So none of the methods work.  My preferred technique is #3.</p>
  
  <p>And just to be clear, my question is how do I subset using my preferred method or one of the other methods?</p>