Skip to content

function in aggregate applied to specific columns only

7 messages · david hilton shanabrook, David Winsemius, milton ruser +3 more

#
On Jan 3, 2010, at 10:46 PM, david hilton shanabrook wrote:

            
> basicSubMean <- aggregate(basicSub$score, by=list(basicSub 
$student), FUN=mean, na.rm=TRUE)
 > basicSubMean
   Group.1    x
1       1 55.0
2       2 60.0
3       3 67.5
#
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:
#
A ninth was detailed in two other threads last month. The first link 
compares to ave().
http://tolstoy.newcastle.edu.au/R/e8/help/09/12/9014.html
http://tolstoy.newcastle.edu.au/R/e8/help/09/12/8830.html

"Dennis Murphy" <djmuser at gmail.com> wrote in message 
news:9a8a6c631001032057qc5cd68j9ec3882043dec0bc at mail.gmail.com...