If I have the function with three individual arguments
fun <- function(a,b,c){
a+b^2*c
}
How can I call it using a single vector
my_vector <- c(1,2,3)
fun(my_vector)
Adding Arguments in R We can pass an argument to a function while calling the function by simply giving the value as an argument inside the parenthesis.
Yes. See the Examples section of ? optim and ? integrate for some R functions that accept other functions as arguments.
try this:
> do.call("fun", as.list(my_vector)) [1] 13
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With