title: applying a function with multiple arguments over multiple paired variables in R
body: <p>I have a function like this which im using to clean data and works correctly.</p>
  
  <pre><code>my_fun &lt;- function (x, y){
      y &lt;- ifelse(str_detect(x, "-*\\d+\\.*\\d*"), 
          as.numeric(str_extract(x, "-*\\d+\\.*\\d*")),
          as.numeric(y))
  }
  </code></pre>
  
  <p>It takes numbers that have been entered in the wrong column and reassigns them to the correct column. It is used as follows to clean the y variable:</p>
  
  <pre><code>df$y &lt;- my_fun(x, y)
  </code></pre>
  
  <p>I have many columns/variables (more than 10) that are paired in the same format something like this </p>
  
  <pre><code>x_vars &lt;- c("x_1", "x_2", "x_3", "x_4", "x_5", "x_6")
  y_vars &lt;- c("y_1", "y_2", "y_3", "y_4", "y_5", "y_6")
  </code></pre>
  
  <p>My question is. Is there a way to apply this function across all the variables in my data set that need to be cleaned in the same way? I can easily do this in other instances where my data cleaning function has only one argument using <code>lapply</code> but am struggling in this case. </p>
  
  <p>I have tried <code>mapply</code> but could not get it to work, this might be because I'm still quite a novice in R. Any advice would be much appreciated. </p>