title: How to subset data.frame by weeks and then sum?
body: <p>Let's say I have several years worth of data which look like the following</p>
  
  <pre><code># load date package and set random seed
  library(lubridate)
  set.seed(42)
  
  # create data.frame of dates and income
  date &lt;- seq(dmy("26-12-2010"), dmy("15-01-2011"), by = "days")
  df &lt;- data.frame(date = date, 
                   wday = wday(date),
                   wday.name = wday(date, label = TRUE, abbr = TRUE),
                   income = round(runif(21, 0, 100)),
                   week = format(date, format="%Y-%U"),
                   stringsAsFactors = FALSE)
  
  #          date wday wday.name income    week
  # 1  2010-12-26    1       Sun     91 2010-52
  # 2  2010-12-27    2       Mon     94 2010-52
  # 3  2010-12-28    3      Tues     29 2010-52
  # 4  2010-12-29    4       Wed     83 2010-52
  # 5  2010-12-30    5     Thurs     64 2010-52
  # 6  2010-12-31    6       Fri     52 2010-52
  # 7  2011-01-01    7       Sat     74 2011-00
  # 8  2011-01-02    1       Sun     13 2011-01
  # 9  2011-01-03    2       Mon     66 2011-01
  # 10 2011-01-04    3      Tues     71 2011-01
  # 11 2011-01-05    4       Wed     46 2011-01
  # 12 2011-01-06    5     Thurs     72 2011-01
  # 13 2011-01-07    6       Fri     93 2011-01
  # 14 2011-01-08    7       Sat     26 2011-01
  # 15 2011-01-09    1       Sun     46 2011-02
  # 16 2011-01-10    2       Mon     94 2011-02
  # 17 2011-01-11    3      Tues     98 2011-02
  # 18 2011-01-12    4       Wed     12 2011-02
  # 19 2011-01-13    5     Thurs     47 2011-02
  # 20 2011-01-14    6       Fri     56 2011-02
  # 21 2011-01-15    7       Sat     90 2011-02
  </code></pre>
  
  <p>I would like to sum 'income' for each week (Sunday thru Saturday). Currently I do the following:</p>
  
  <pre><code>Weekending 2011-01-01 = sum(df$income[1:7]) = 487
  Weekending 2011-01-08 = sum(df$income[8:14]) = 387
  Weekending 2011-01-15 = sum(df$income[15:21]) = 443
  </code></pre>
  
  <p>However I would like a more robust approach which will automatically sum by week. I can't work out how to automatically subset the data into weeks. Any help would be much appreciated.</p>