title: R - add column based on intervals in separate data frame
body: <p>I have the following data frames:</p>
  
  <pre><code>DF &lt;- data.frame(Time=c(1:20))
  StartEnd &lt;- data.frame(Start=c(2,6,14,19), End=c(4,10,17,20))
  </code></pre>
  
  <p>I want to add a column "Activity" to DF if the values in the Time column lie inbetween one of the intervals specified in the StartEnd dataframe.</p>
  
  <p>I came up with the following: </p>
  
  <pre><code>mapply(FUN = function(Start,End) ifelse(DF$Time &gt;= Start &amp; DF$Time &lt;= End, 1, 0), 
    Start=StartEnd$Start, End=StartEnd$End)
  </code></pre>
  
  <p>This doesn't give me the output I want (it gives me a matrix with four columns), but I would like to get a vector that I can add to DF.</p>
  
  <p>I guess the solution is easy but I'm not seeing it :) Thank you in advance.</p>
  
  <p>EDIT: I'm sure I can use a loop but I'm wondering if there are more elegant solutions. </p>