This was the correct answer:
percentage_of_goals <- function(x,y) {
xy_total = x + y
(x/xy_total) * 100
}
home_percent <- percentage_of_goals(scores$home_goals, scores$away_goals)
My question is below:
Why is it not necessary to have your initial function have a (y/xy_total) * 100 as well ? If we have 2 arguments shouldn’t we take into account both the home_goals and away_goals as x and y as well ?
percentage_of_goals <- function(x,y) {
xy_total = x + y
(x/xy_total) * 100
(y/xy_total) * 100
}