[R] sum(..., na.rm=TRUE) oddity
Duncan Murdoch
dmurdoch at pair.com
Mon Apr 28 14:15:08 CEST 2003
On Mon, 28 Apr 2003 12:28:32 +0100, Barry Rowlingson
<B.Rowlingson at lancaster.ac.uk> wrote:
> Are you certain you typed 'na.rm'? I have occasionally typed 'rm.na'
>instead, and something like that might explain things:
>
>
> > sum(1,1,na.rm=TRUE)
>[1] 2
>
> > sum(1,1,rm.na=TRUE)
>[1] 3
Is there ever any reason to name the summands? I'd think it would be
reasonable to generate an error, or at least a warning, in a case
where any of the arguments to be summed are named. For example
sum <- function (..., na.rm = FALSE) {
if (!is.null(names(list(...))))
stop(paste('Named summands:',paste(names(list(...)),collapse='
')))
.Internal(sum(..., na.rm = na.rm))
}
gives this:
> sum(1,1,rm.na=TRUE)
Error in sum(1, 1, rm.na = TRUE) : Named summands: rm.na
Duncan Murdoch
More information about the R-help
mailing list