Reputation: 1769
I have the following function:
I would like to write a function in R
for f
. It should take as arguments x
, c1
, ..., cn
and n
.
Upvotes: 4
Views: 477
Reputation: 887531
If the argument lengths are variable, use 3 dots (...
)
f1 <- function(x, ...) {
2 * x + sum((x - c(...))^2)
}
-testing
f1(5, 10, 5, 2, 3)
[1] 48
Upvotes: 7