I wrote a function that further processes the input dataframe, say excludes participants with a valuevariable > 3. For example:
function.example <- function(dataframe, valuevariable, conditionvariable) {
processed.dataframe <- dataframe %>% filter(valuevariable > 3)
....#more code
}
and you call the function like this: function.example(df, df$latency, df$group)
Now, say I want to access the conditionvariable of processed.dataframe the function
Typically, you´d do that with processed.dataframe$group
.
For example:
function.example <- function(dataframe, valuevariable, conditionvariable) {
processed.dataframe <- dataframe %>% filter(valuevariable > 3)
#say I now want to make sure the conditionvariable is a factor
processed.dataframe$conditionvariable <- as.factor(processed.dataframe$conditionvariable)
}
The problem is that I cannot call the group variable by $conditionvariable
, I need to write $group
. Now, if I have diverse datasets, the conditionvariable will not be called group every time. Hence, I´m looking for a way to access processed.dataframe$[name conditionvariable] regardless of the way the conditionvariable is called. Does anyone know how to do that?