[R] fun.aggregate=mean in reshape

jiho jo.irisson at gmail.com
Tue Feb 12 11:37:31 CET 2008


On 2008-February-12  , at 11:11 , Henrique Dallazuanna wrote:
> You can use aggregate:
>
> aggregate(data[,c("ozone", "solar.r", "wind", "temp")],
> list(month=data$month), mean)
>
> On 12/02/2008, [Ricardo Rodriguez] Your XEN ICT Team <webmaster at xen.net 
> > wrote:
>> Hi all,
>>
>> We are facing a problem while introducing ourselves to Reshape  
>> package
>> use. Melt seems to work fine, but cast fails when we use mean as
>> fun.aggregate. As you see here, length and sum work fine, but mean
>> throws this same error whatever dataset we use.
>>
>>> cast(aqm, month ~ variable, length)
>>  month ozone solar.r wind temp
>> 1     5    26      27   31   31
>> 2     6     9      30   30   30
>> 3     7    26      31   31   31
>> 4     8    26      28   31   31
>> 5     9    29      30   30   30
>>> cast(aqm, month ~ variable, sum)
>>  month ozone solar.r  wind temp
>> 1     5   614    4895 360.3 2032
>> 2     6   265    5705 308.0 2373
>> 3     7  1537    6711 277.2 2601
>> 4     8  1559    4812 272.6 2603
>> 5     9   912    5023 305.4 2307
>>> cast(aqm, month ~ variable, mean)
>> Error in get(as.character(FUN), mode = "function", envir = envir) :
>>  variable "fun" of mode "function" was not found
>>>
>>
>>
>> Our environment:
>>
>>> version
>>               _
>> platform       i386-apple-darwin8.10.1
>> arch           i386
>> os             darwin8.10.1
>> system         i386, darwin8.10.1
>> status
>> major          2
>> minor          6.2
>> year           2008
>> month          02
>> day            08
>> svn rev        44383
>> language       R
>> version.string R version 2.6.2 (2008-02-08)
>>
>>
>>> installed.packages()
>>
>> reshape    "reshape"
>> "/Library/Frameworks/R.framework/Resources/library" "0.8.0"
>> NA            NA
>>
>>
>> Please, could you help use to work out this issue? Thanks!

It probably won't help much, but may be interesting for diagnostic  
purposes: it works for me on the same environment except for R 2.6.1  
instead of 2.6.2.
Have you tried specifying the argument name explicitely?

JiHO
---
http://jo.irisson.free.fr/



More information about the R-help mailing list