This question will be bountied by me eventually if no one gives a satisfactory answer.
I have the following code in R
library(dplyr)
Data <- iris %>% filter(Petal.Length > 5)
The filter
function calls upon the iris object and subsets the data by the Petal.Length
variable.
What I want is to be able to pass a string through the filter function such that something like this would give the same result.
Data <- iris %>% filter(get("Sepal.Length") > 5)
The above code gives an error though
Error: object 'Sepal.Length' not found
If it's of any benefit for context, get
works with the select
function within dplyr
. For example...
Data <- iris %>% select(Sepal.Length)
Data1 <- iris %>% select(get("Sepal.Length"))
give the same results.
Is there any way to make it such that the two filter
statements, where one could pass a string through the latter one, would give the same output?