title: Using the result of summarise (dplyr) to mutate the original dataframe
body: <p>I have a rather big dataframe with a column of POSIXct datetimes (~10yr of hourly data). I would flag all the rows in which the day falls in a Daylight saving period. For example if the Daylight shift starts on '2000-04-02 03:00:00' (DOY=93) i would like that the two previous hours of DOY=93 could be flagged.
  Although I am a newbie of dplyr I would use this package as much as possible and avoid <em>for-loops</em> as much as possible</p>
  
  <p>For example:</p>
  
  <pre><code>library(lubridate)
  sd = ymd('2000-01-01',tz="America/Denver")
  ed = ymd('2005-12-31',tz="America/Denver")
  span = data.frame(date=seq(from=sd,to=ed, by="hour"))
  span$YEAR = year(span$date)
  span$DOY = yday(span$date)
  span$DLS = dst(span$date)
  </code></pre>
  
  <p>To find the different days of the year in which the daylight saving is applied I use dplyr</p>
  
  <pre><code>library(dplyr)
  limits = span %.% group_by(YEAR) %.% summarise(minDOY=min(DOY[DLS]),maxDOY=max(DOY[DLS]))
  </code></pre>
  
  <p>That gives</p>
  
  <pre><code>      YEAR minDOY maxDOY
      1 2000     93    303
      2 2001     91    301
      3 2002     97    300
      4 2003     96    299
      5 2004     95    305
      6 2005     93    303
  </code></pre>
  
  <p>Now I would 'pipe' the above results in the <em>span</em> dataframe without using a inefficient <em>for-loop</em>.</p>
  
  <h2>SOLUTION 1</h2>
  
  <p>with the help of @aosmith the problem can be tackled with just two commands (and avoiding the inner_join as in 'solution 2'):</p>
  
  <pre><code> limits = span %&gt;% group_by(YEAR) %&gt;% mutate(minDOY=min(DOY[DLS]),maxDOY=max(DOY[DLS]),CHECK=FALSE)
  
   limits$CHECK[(limits2$DOY &gt;= limits$minDOY) &amp; (limits$DOY &lt;= limits$maxDOY) ] = TRUE      
  </code></pre>
  
  <h2>SOLUTION 2</h2>
  
  <p>With the help of @beetroot and @matthew-plourde, the problem has been solved:
  an inner-join between was missing:</p>
  
  <pre><code>limits = span %&gt;% group_by(YEAR) %&gt;% summarise(minDOY=min(DOY[DLS]),maxDOY=max(DOY[DLS])) %&gt;% inner_join(span, by='YEAR')
  </code></pre>
  
  <p>Then I just added a new column (CHECK) to fill with the right values for the Daylight-savings days</p>
  
  <pre><code>limits$CHECK = FALSE
  limits$CHECK[(limits$DOY &gt;= limits$minDOY) &amp; (limits$DOY &lt;= limits$maxDOY) ] = TRUE
  </code></pre>