title: Turning a formula to a function
body: <p>I have the following formula of relative estimation error that I am trying to turn into a function to measure the precision of measurements.</p>
  <p><a href="https://i.stack.imgur.com/WyFFh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WyFFh.png" alt="enter image description here" /></a></p>
  <p>Where:</p>
  <p><strong>Y_estimated</strong> = the observed values in the test df</p>
  <p><strong>y_true</strong> = the true value that we are trying to estimate (denoted as p_true in code)</p>
  <p><strong>R</strong> = the number of observations in each iteration (n=3)</p>
  <p>My data has the following format:</p>
  <pre><code># dataframe
  test&lt;- iris[1:3,1:4]
  
  # make a vector that shows the true population value for each column in the dataframe
  p_true&lt;- c(5, 3, 1, 0.3)
  
  # function
  estimate = function(df, y_true) {
    
    ((sqrt(sum((df - y_true) ^ 2)) / 3) / y_true) * 100 
  }                                                           
  
  y_true &lt;- p_true
  
  
  final2 &lt;- test %&gt;%
    group_modify( ~ as.data.frame(estimate(., p_true)))
  </code></pre>
  <p>The goal is to have an output of 1 row of  4 precision estimates (one for each variable). Apart from the current output format being put into 1 column and 4 rows instead of 4 columns and 1 row, I'm not sure if the function is set up correctly as the values are much more extreme than I am expecting to get.</p>
  <p>If anyone can confirm if my function is set up correctly and/or how to get the output to be in the correct format I would really appreciate the help.</p>