From murdoch at stats.uwo.ca  Tue Mar 24 12:07:28 2009
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Tue, 24 Mar 2009 07:07:28 -0400
Subject: [Rd] Is aggregate() function changing?
In-Reply-To: <1237869849.2652.17.camel@localhost>
References: <1237869849.2652.17.camel@localhost>
Message-ID: <49C8BEF0.9030805@stats.uwo.ca>

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.

Duncan Murdoch


> 
> Thank you for your attention.
> 
> Kenneth.
>> sessionInfo()
> 
> R version 2.8.1 Patched (2009-03-18 r48193) 
> x86_64-unknown-linux-gnu 
> 
> locale:
> LC_CTYPE=es_CO.UTF-8;LC_NUMERIC=C;LC_TIME=es_CO.UTF-8;LC_COLLATE=es_CO.UTF-8;LC_MONETARY=C;LC_MESSAGES=es_CO.UTF-8;LC_PAPER=es_CO.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=es_CO.UTF-8;LC_IDENTIFICATION=C
> 
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Is aggregate() function changing?
Duncan Murdoch