title: How to loop a double-conditional over a vector
body: <p>Halloo! I've hit a snag trying to automate an ifelse statement with two conditions... I've generated a fake value for every minute in a day and want to group values by intervals - hourly, every 5 mins, every twenty, whathaveyou - but the only way I've been able thus far to group by these intervals is brute force:</p>
  <pre><code>d$hourly &lt;- ifelse(d$t &gt;= 0 &amp; d$t &lt;= 60, 0, 
         ifelse(d$t &gt; 60 &amp; d$t &lt;= 120, 1, 
         ifelse(d$t &gt; 121 &amp; d$t &lt;= 180, 2, 
         ifelse(d$t &gt; 180 &amp; d$t &lt;= 240, 3, 
         ifelse(d$t &gt; 240 &amp; d$t &lt;= 300, 4,
         ifelse(d$t &gt; 300 &amp; d$t &lt;= 360, 5,
         ifelse(d$t &gt; 360 &amp; d$t &lt;= 420, 6, 
         ifelse(d$t &gt; 420 &amp; d$t &lt;= 480, 7, 
         ifelse(d$t &gt; 480 &amp; d$t &lt;= 520, 8,
         ifelse(d$t &gt; 520 &amp; d$t &lt;= 600, 9,
         ifelse(d$t &gt; 600 &amp; d$t &lt;= 660, 10,
         ifelse(d$t &gt; 660 &amp; d$t &lt;= 720, 11, 
         ifelse(d$t &gt; 720 &amp; d$t &lt;= 780, 12, 
         ifelse(d$t &gt; 780 &amp; d$t &lt;= 840, 13, 
         ifelse(d$t &gt; 840 &amp; d$t &lt;= 900, 14, 
         ifelse(d$t &gt; 900 &amp; d$t &lt;= 960, 15,
         ifelse(d$t &gt; 960 &amp; d$t &lt;= 1020, 16,
         ifelse(d$t &gt; 1020 &amp; d$t &lt;= 1080, 17,                                     
         ifelse(d$t &gt; 1080 &amp; d$t &lt;= 1140, 18, 
         ifelse(d$t &gt; 1140 &amp; d$t &lt;= 1200, 19,
         ifelse(d$t &gt; 1200 &amp; d$t &lt;= 1260, 20, 
         ifelse(d$t &gt; 1260 &amp; d$t &lt;= 1320, 21,                                     
         ifelse(d$t &gt; 1320 &amp; d$t &lt;= 1380, 22, 
         ifelse(d$t &gt; 1380 &amp; d$t &lt;= 1440, 23, NA))))))))))))))))))))))))
  </code></pre>
  <p>presumably, there is something I am not understanding about for(i in 1:nrow) or other looped functions. Is there a cleaner way to loop conditionals over a vector?</p>
  <p>Many thanks!</p>