On Tue, Mar 24, 2009 at 7:07 AM, Duncan Murdoch <murd...@stats.uwo.ca> wrote: > On 24/03/2009 12:44 AM, Kenneth Roy Cabrera Torres wrote: >> >> Hi R developers and debian users: >> >> Finally I found how to work with aggregate() function >> on the last patched version fo R. >> >> I you use this command it fails: >> aggregate(state.x77, list(Region = state.region), mean) >> >> But if you modify it in this way, it works!: >> >> aggregate(state.x77, list(Region = state.region), function(x) mean(x) ) >> >> Is it necesary to change the example? >> >> What is changing in aggregate() function? > > I get identical results from those, but if I had a local variable (not a > function) named "mean", the first one would not work: > >> mean <- 2 >> aggregate(state.x77, list(Region = state.region), mean) > Error in FUN(X[[1L]], ...) : element 1 is empty; > the part of the args list of 'is.list' being evaluated was: > (INDEX) > > I suspect that is what is going wrong for you. >
although "mean" in quotes works even then: > mean <- 1 > aggregate(state.x77, list(Region = state.region), "mean") Region Population Income Illiteracy Life Exp Murder HS Grad 1 Northeast 5495.111 4570.222 1.000000 71.26444 4.722222 53.96667 2 South 4208.125 4011.938 1.737500 69.70625 10.581250 44.34375 3 North Central 4803.000 4611.083 0.700000 71.76667 5.275000 54.51667 4 West 2915.308 4702.615 1.023077 71.23462 7.215385 62.00000 Frost Area 1 132.7778 18141.00 2 64.6250 54605.12 3 138.8333 62652.00 4 102.1538 134463.00 ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel