# mean(c(1,2,3))
mean(1, 2, 3)
[1] 1
mean(c(1, 2), 3)
[1] 1.5
Notes on functions
Chi Zhang
October 6, 2023
Special argument ...
. This type of argument is varargs (variable arguments). The function can take any numbers of arguments.
Primary uses:
Downsides:
mean(x, ...)
The ...
can be something like na.rm = F
.
Given that the first argument is being averaged upon, if a vector is not specified correctly, only the first element is being averaged; and the other elements are treated as additional arguments that are not necessarily used.
[[1]]
[1] 6
[[1]]
[1] 6
[[2]]
[1] 4