I'm trying to make a function that takes two arguments. One argument is the name of a data frame, and the second is the name of a column in that data frame. The goal is for the function to manipulate data in the whole frame based on information contained in the specified column.
My problem is that I can't figure out how to use the character expression entered into the second argument to access that particular column in the data frame within the function. Here's a super brief example,
datFunc <- function(dataFrame = NULL, charExpres = NULL) {
return(dataFrame$charExpress)
}
If, for instance you enter
datFunc(myData, "variable1")
this does not return myData$variable1. there HAS to be a simple way to do this. Sorry if the question is stupid, but i'd appreciate a little help here.
A related question would be, how do i use the character string "myData$variable1" to actually return variable1 from myData?
return(dataFrame[[charExpress]])?