I'm experiencing some confusion with the ellipsis argument
(...).
In my .Rprofile, I have the following functions:
stderr <- function(x, ...) {
sqrt( var(x, ...) / length(x) )
}
se <- stderr
I can use tapply to calculate some means:
> tapply( Diameter, factor(Region), mean, na.rm=TRUE )
I II III IV V
0.02896429 0.02368421 0.03990476 0.03949315 0.03424021
but, it I try to use my se function, I get an unused argument(s)
error...
> tapply( Diameter, factor(Region), se, na.rm=TRUE )
Error in FUN(X[[1]], ...) : unused argument(s) (na.rm ...)
If I use stderr instead, I don't get that error:
> tapply( Diameter, factor(Region), stderr, na.rm=TRUE )
I II III IV V
0.005167949 0.004405095 0.006588870 0.006633189 0.001857812
I'm curious about what's going on here. Any ideas? Is it just
that `...' can only be used in directly defined functions and not
by objects that reference functions?
Regards, Mike Miller
P.S. I'm using R.Version()
$platform
[1] "i386-pc-linux-gnu"
$arch
[1] "i386"
$os
[1] "linux-gnu"
$system
[1] "i386, linux-gnu"
$status
[1] ""
$major
[1] "1"
$minor
[1] "3.0"
$year
[1] "2001"
$month
[1] "06"
$day
[1] "22"
$language
[1] "R"
--
Michael A. Miller mmiller3 at iupui.edu
Krannert Institute of Cardiology, IU School of Medicine
Indiana Center for Vascular Biology and Medicine
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On 30 Jul 2001, Michael A. Miller wrote:> I'm experiencing some confusion with the ellipsis argument > (...). > > In my .Rprofile, I have the following functions: > > stderr <- function(x, ...) { > sqrt( var(x, ...) / length(x) ) > } > se <- stderr > > I can use tapply to calculate some means: > > > tapply( Diameter, factor(Region), mean, na.rm=TRUE ) > I II III IV V > 0.02896429 0.02368421 0.03990476 0.03949315 0.03424021 > > but, it I try to use my se function, I get an unused argument(s) > error... > > > tapply( Diameter, factor(Region), se, na.rm=TRUE ) > Error in FUN(X[[1]], ...) : unused argument(s) (na.rm ...) > > If I use stderr instead, I don't get that error: > > > tapply( Diameter, factor(Region), stderr, na.rm=TRUE ) > I II III IV V > 0.005167949 0.004405095 0.006588870 0.006633189 0.001857812 > > I'm curious about what's going on here. Any ideas? Is it just > that `...' can only be used in directly defined functions and not > by objects that reference functions?Not so. I can't reproduce this putting that code in my .Rprofile. See ?Startup: .RData is loaded after .Rprofile, so do you have a function se() in your .RData? -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
mmiller3 at iupui.edu (Michael A. Miller) writes:> I'm experiencing some confusion with the ellipsis argument > (...). > > In my .Rprofile, I have the following functions: > > stderr <- function(x, ...) { > sqrt( var(x, ...) / length(x) ) > } > se <- stderr...> If I use stderr instead, I don't get that error: > > > tapply( Diameter, factor(Region), stderr, na.rm=TRUE ) > I II III IV V > 0.005167949 0.004405095 0.006588870 0.006633189 0.001857812I know that's not what you were asking, but you're not getting the correct result either... You'd need to divide by sum(!is.na(x)) rather than length(x). -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._