Thank you for the explanation.
But if you take for instance plot.default(), being another generic
function, it would not work like that:
plot(1,2,3,4), only plot(1,2) is accepted.
From R-help (Usage):
## Default S3 method:
mean(x, trim = 0, na.rm = FALSE, ...)
What is puzzling, is that apparently na.rm (and trim, which is indicated in the
help) is accepting numeric values.
mean(c(1,NA,10),10,TRUE)
mean(c(1,NA,10),10,FALSE)
This should give at least a warning in my opinion.
mean(c(1,NA,10),10,200)
On 08/06/2015 09:27, Achim Zeileis wrote:
> On Mon, 8 Jun 2015, Christian Brandst?tter wrote:
>
>> Dear list,
>>
>> I found an odd behavior of the mean function; it is allowed to do
>> something that you probably shouldn't:
>> If you calculate mean() of a sequence of numbers (without declaring
>> them as vector), mean() then just computes mean() of the first
>> element. Is there a reason why there is no warning, like in sd for
>> example?
>
> mean() - unlike sd() - is a generic function that has a '...'
argument
> that is passed on to its methods. The default method which is called
> in your example also has a '...' argument (because the generic has
it)
> but doesn't use it.
>
>> Example code:
>> mean(1,2,3,4)
>> sd(1,2,3,4)
>>
>> Best regards
>> Christian
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
[[alternative HTML version deleted]]