title: check if any values are in a range
body: <p>For a set of observations I have dates of response events.</p>
  
  <pre><code>structure(list(Date1_P2 = structure(c(14061, 14944, 14944), class = "Date"), 
      Date2_P2 = structure(c(NA, 11566, 11747), class = "Date"), 
      Date3_P2 = structure(c(NA, 10408, 11627), class = "Date"), 
      Date4_P2 = structure(c(NA, 8370, 11566), class = "Date")), .Names = c("Date1_P2", 
  "Date2_P2", "Date3_P2", "Date4_P2"), row.names = c(NA, 3L), class = "data.frame")
  &gt; dates
      Date1_P2   Date2_P2   Date3_P2   Date4_P2
  1 2008-07-01       &lt;NA&gt;       &lt;NA&gt;       &lt;NA&gt;
  2 2010-12-01 2001-09-01 1998-07-01 1992-12-01
  3 2010-12-01 2002-03-01 2001-11-01 2001-09-01
  </code></pre>
  
  <p>I want to create a variable that is <code>TRUE</code> if any of these dates falls within a range of a triggering event. Say, something happened in September 2001 that the observations could have responded to or anticipated. I have written the following function,</p>
  
  <pre><code>checkmove &lt;- function(event, range, moves){
    moves &lt;- as.numeric(moves)
    early &lt;- as.numeric(event - range)
    late  &lt;- as.numeric(event + range)
    moved &lt;- any(moves &gt; early &amp; moves &lt; late, na.rm=TRUE) 
    return(moved)
  }
  </code></pre>
  
  <p>If there is a response within 180 days on either side of the event, the value should be <code>TRUE</code>. The function works line by line, but I can't get it to work on the full table.</p>
  
  <pre><code># This is right
  &gt; checkmove(as.Date("2001-09-01"), 180, dates[1,])
  [1] FALSE
  &gt; checkmove(as.Date("2001-09-01"), 180, dates[2,])
  [1] TRUE
  &gt; checkmove(as.Date("2001-09-01"), 180, dates[3,])
  [1] TRUE
  # This is wrong
  &gt; apply(dates, 1, function(x) checkmove(as.Date("2001-09-01"), 180, x))
      1     2     3 
  FALSE FALSE FALSE 
  Warning messages:
  1: In checkmove(as.Date("2001-09-01"), 180, x) :
    NAs introduced by coercion
  2: In checkmove(as.Date("2001-09-01"), 180, x) :
    NAs introduced by coercion
  3: In checkmove(as.Date("2001-09-01"), 180, x) :
    NAs introduced by coercion
  </code></pre>
  
  <p>Am I not using the right <code>apply</code> function? I'd really rather avoid a <code>for</code> loop. Is there a better way to go about this to begin with?</p>