0

我知道mean(2,3,4)错了,但我仍然得到结果2,R如何解析mean(2,3,4),函数如何解析额外参数3,4

> mean(2,3,4)
[1] 2
> mean(c(2,3,4))
[1] 3
4

1 回答 1

3

R 文档:

 mean(x, ...)

 ## Default S3 method:
 mean(x, trim = 0, na.rm = FALSE, ...)

所以mean(2, 3, 4)被解释为mean(x=2, trim=3, na.rm=4)where4被评估为TRUE

作为一个简单的证明,我们可以使用它:

> mean(2, 3, NA)
Error in if (na.rm) x <- x[!is.na(x)] : 
missing value where TRUE/FALSE needed

或这个:

>  mean(NA, 3, 4)
[1] NaN

>  mean(NA, 3, 0)
[1] NA
于 2013-10-20T04:46:26.020 回答