title: R: Frequency and mean of variables
body: <p>I have the following problem: I have the following table:</p>
  
  <pre><code>&gt; data
      StartPoint EndPoint timeDiff
  1         A91    TX043      258
  2         A91    TX048      547
  3         A92    TX088      330
  4         A91    TX088      289
  5         A91    TX043      387
  6         A92    TX088      241
  7         A91    TX088      213
  8         A92    TX043      295
  9         A91    TX088      518
  10        A92    TX088      414
  </code></pre>
  
  <p>I would need an aggregation of the following form:</p>
  
  <pre><code>StartPoint  EndPoint  count  mean(timeDiff)
     A91         TX088    3    mean of 289,213 and 518
     A91         TX043    2    mean of 258 and 387
     A91         TX048    1     547
     A92         TX088    3    mean of 330, 241 and 414
     A92         TX043    1     295
  </code></pre>
  
  <p>count is the number of occurences of same StartPoint and EndPoint pair and mean is the average of the timeDiff of the entries with same StartPoint and EndPoint pair. The result should be sorted on StartPoint, count and EndPoint.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Thanks in advance,
  Sugi</p>
  
  <p>my data:</p>
  
  <pre><code>data &lt;- structure(list(StartPoint = c("A91", "A91", "A92", "A91", "A91", "A92", "A91", "A92", "A91", "A92"), EndPoint = c("TX043", "TX048", "TX088", "TX088", "TX043", "TX088", "TX088", "TX043", "TX088", "TX088"), timeDiff = c(258, 547, 330, 289, 387, 241, 213, 295, 518, 414)), .Names = c("StartPoint", "EndPoint", "timeDiff"), row.names = c(NA, 10L), class = "data.frame")
  </code></pre>