[R] fun.aggregate=mean in reshape
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Tue Feb 12 13:16:38 CET 2008
[Ricardo Rodriguez] Your XEN ICT Team said the following on 2/12/2008
12:23 AM:
> 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!
>
Do you have an object called 'mean' that's masking the base::mean
function? I can replicate your error using the following:
> library(reshape)
> names(airquality) <- tolower(names(airquality))
> aqm <- melt(airquality, id=c("month", "day"), na.rm=TRUE)
> mean <- 1
> cast(aqm, month ~ variable, mean)
Error in get(as.character(FUN), mode = "function", envir = envir) :
variable "fun" of mode "function" was not found
> cast(aqm, month ~ variable, base::mean)
month ozone solar.r wind temp
1 5 23.61538 181.2963 11.622581 65.54839
2 6 29.44444 190.1667 10.266667 79.10000
3 7 59.11538 216.4839 8.941935 83.90323
4 8 59.96154 171.8571 8.793548 83.96774
5 9 31.44828 167.4333 10.180000 76.90000
> find("mean")
[1] ".GlobalEnv" "package:base"
HTH,
--sundar
More information about the R-help
mailing list