I'm trying to create a new variable using mutate() based on conditions occurring in other variables (that may or may not exist). I would love to use any_of() but that only works with a select()
Basically I would lover to implement something like this:
But both don't work if a variable doesn't exist. The reason I want to do this is that I want to loop it over several dataframes/files. Some of them will have all of those variables (columns, that, maynot, exist, cyl, gear). Some will only have "cyl" and "gear" and some other may have another selection of the full list. Mutate does not work if the variables/columns you mention don't exist. Anyone has an idea how I would be able to implement this?
I'm glad you worked it out.
I wanted to write it all in one line, or pipe it together,
but the people who design the tidyverse might say that forcing the code to be complicated is a bad attempt, so I decided to split the code.