0

Let's say I have the following scenario. My dataset changes monthly to where it uses the last day of the month + "Record Created".

So to avoid changing this multiple times in the dplyr pipe function, I want to pre-defined this variable in the global environment, so in dplyr, I can call the Columnparam in my select, filter and summarize functions.

Columnparam <- "7/31 Record Created"
analysis <- data %>% 
     filter(Columnparam == "YES")

Unfortunately, this doesn't work. Because it's looking for a "Columnparam" in the dataset, which doesn't exist.

How can I get it to call the "7/31 Record Created" string I defined in the global environment?

Neo Anderson
  • 5,957
  • 2
  • 12
  • 29
miikey722
  • 45
  • 4
  • How about reshaping your data frame such that you can have a column `Columnparam` and thus call `filter(Columnparam == "7/31 Record Created")`? – BroVic Aug 17 '20 at 18:57

1 Answers1

0

You can try data %>% filter(!!as.symbol(Columnparam) == "YES"). See also Filter data frame by character column name (in dplyr) for more information.

piptoma
  • 754
  • 1
  • 8
  • 19