I am trying to make a function that does a simple calculation, however, I want to apply it across several columns, and each column has a different constant in the equation.
This is the formula I want to make into a function.
Example
df<- iris[1:10,2:4]
y_true<- c(3, 1, 0.4) # each number(constant) corresponds to each column in df
y_true_sepal_width<- 3 # (1 corresponds to petal.length, 0.4 to petal.width)
R<- 10 # Number of samples
y_estimated<- mean(df$Sepal.Width)
(((sqrt((y_estimated-y_true_sepal_width)^2/R))*100)) #This is (I believe) how to find the value for one column manually
I want to do this formula, but basically taking the mean of each column and substituting out each y_true as it moves across the data frame. I figured this would be done by putting the true constants into a vector, but haven't had any luck in incorporating it into the function.