Skip to content
Prev 205287 / 398506 Next

function in aggregate applied to specific columns only

Here are 6 ways:

1. aggregate
student score
1       1  55.0
2       2  60.0
3       3  67.5

2. tapply
1    2    3
55.0 60.0 67.5

3. summaryBy in doBy package
student score.mean
1       1       55.0
2       2       60.0
3       3       67.5

4. sqldf in sqldf package.  Uses SQL:
student avg(score)
1       1       55.0
2       2       60.0
3       3       67.5

5. summary.formula in Hmisc
score    N=5

+-------+-+-+-----+
|       | |N|score|
+-------+-+-+-----+
|student|1|2|55.0 |
|       |2|1|60.0 |
|       |3|2|67.5 |
+-------+-+-+-----+
|Overall| |5|61.0 |
+-------+-+-+-----+

6. plyr (see Dennis Murphy's solution in this thread)


On Sun, Jan 3, 2010 at 10:46 PM, david hilton shanabrook
<dhshanab at acad.umass.edu> wrote: