I have a dataset called df, which has columns a and b with three integers each. I want to write a function for the mean (obviously this already exists; I want to write a larger function and this appears to be where problems are occurring). However, this function returns NA:
mean_function <- function(x) {
mean(df$x)
}
mean_function(a)
returns NA
, while mean(df$a)
returns 2
. Is there something I'm missing about how R functions handle datasets, or another problem?