0

I would like to create something like a loop, where I get a vector with two elements. The first element should be the result of the function when the first element of vec_a and vec_b are inserted into the function:

example_function(parameter1 = vec_a[1], parameter2 = var_x, parameter3 = vec_b[1], parameter4 = var_y)

and the second element should be the result of this:

example_function(parameter1 = vec_a[2], parameter2 = var_x, parameter3 = vec_b[2], parameter4 = var_y)

Where those are the inputs:

vec_a <- c(1.01,1.42)

vec_b <- c(2.11, 1.99)

var_x <- 2

var_y <- 53.97

Thanks a lot in advance for your help.

wind_2801
  • 131
  • 10
  • Look at the `?Vectorize` function. You can vectorize over whatever parameters you like. It would be easier to be more specific if you provided a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that could actually be run. Many functions in R might do this already. – MrFlick Oct 19 '17 at 14:04
  • Consider mapply: `mapply(example_function, vec_a, var_x, vec_b, var_y)` – Parfait Oct 19 '17 at 14:09
  • thank you Parfait! The mapply function worked like a charm. – wind_2801 Oct 19 '17 at 15:18

0 Answers0