[R] Problems with aggregate() function in stats package

Jon Zadra jrz9f at virginia.edu
Thu Sep 15 23:07:11 CEST 2011


Hi,

I'm having some problems with the aggregate() function in the {stats} 
package, and the documentation doesn't address them.

1) Why would the first line work, but the second not? According to the 
help file, it accepts a "data=" argument.

>  with(tsrc, aggregate(x=DistRatio, by=list(Condition), FUN=mean))
     Group.1        x
1 Congruent 1.741789
2  Mismatch 1.771425

>  aggregate(x=DistRatio, by=list(Condition), data=tsrc, FUN=mean)
Error in aggregate(x = DistRatio, by = list(Condition), data = tsrc, FUN = mean) :
   object 'DistRatio' not found


2) The subset argument also does not appear to work (perhaps this is the 
same issue?):

>  with(tsrc, aggregate(x=DistRatio, by=list(Condition), subset=Drop!="Yes", FUN=mean))
     Group.1        x
1 Congruent 1.741789
2  Mismatch 1.771425

>  with(tsrc[tsrc$Drop!="Yes",], aggregate(x=DistRatio, by=list(Condition), FUN=mean))
     Group.1        x
1 Congruent 1.700215
2  Mismatch 1.859795


So, am I doing something wrong or is this function just not working as 
advertised?

Thanks,

Jon

-- 
Jon Zadra
Department of Psychology
University of Virginia
P.O. Box 400400
Charlottesville VA 22904
(434) 982-4744
email: zadra at virginia.edu
<http://www.google.com/calendar/embed?src=jzadra%40gmail.com>



More information about the R-help mailing list