title: Create a table with mean duration times per years and types
body: <p>I have the following dataframe:</p>
  
  <pre><code>library("lubridate")
  
  df = data.frame(c("AAA","BBB","AAA"),
                  c("2012","2013","2012"),
                  c("2012-12-30 08:01:01","2013-12-30 09:05:02","2012-12-30 08:08:01"),
                  c("2012-12-30 09:01:00","2013-12-30 10:15:00","2012-12-30 08:11:01"))
  colnames(df) = c("type","year","start","end")
  
  df$duration = difftime(ymd_hms(df$end), ymd_hms(df$start),units="mins")
  </code></pre>
  
  <p>Now I want to create a table with mean durations so that it would look as follows:</p>
  
  <pre><code>     2012   2013
  AAA  31.49  0.00
  BBB  0.00   69.97
  </code></pre>
  
  <p>Which functions should I use to create such table?</p>
  
  <p>Update:</p>
  
  <p>This is what I tried, but how can I add <code>year</code>?:</p>
  
  <pre><code>mean_duration_per_type_year = aggregate(duration~type,
                                          data=df,
                                          mean)
  </code></pre>