Here’s my guess at what might work the way you wanted:
elbow <- function(arg1,arg2) { my_data <- read.csv("data.csv", header=TRUE, sep=",") average_A <- my_data[[arg1]] + my_data[[arg2]] # "[[" evaluates args average_A } elbow('A3','A5') # entered a character literals
You should realize that the rest of my_data will have evaporated and be garbage collected after return from the elbow
call. I could have showed you how to use your original expression following attach()
, which would have been arguably safe within that function, but that would have violated my religious principles.