'How can I expand a vector into the arguments of a function in r?
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)
Solution 1:[1]
This should work!
fun(1,2,3)
Otherwise,
fun <- function(x){
x[1]+x[2]^2*x[3]
}
fun(c(1,2,3))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | yc_hello |
