I have the following function:
estimate = function(df, y_true) {
        
        R = nrow(df)
        
        y_estimated = apply(df, 2, mean)
        
        ((sqrt( (y_estimated - y_true)^2 / R)) / y_true) * 100
}
df = iris[1:10,2:4]
y_true = c(3, 1, 0.4)
estimate(df = df, y_true = y_true)
user:bird provided this and works great, however, I also need to find the means by group. So if we change the df to df= iris[,2:5], how to do I find the means of each column by Species to use in the function. I figured something like this would work- but not luck:
estimate = function(df, y_true, group) {
  
  R = nrow(df)
  
  y_estimated = df %>% group_by(group) %>% apply(df, 2, mean)
  
  ((sqrt( (y_estimated - y_true)^2 / R)) / y_true) * 100
}
df = iris[2:5]
y_true = c(3, 1, 0.4)
group=df$Species 
estimate(df = df, y_true = y_true, group=group)
Using colMeans also did not work.
This is an extension of this post which explains the purpose of each variable.