I need some help with user defined functions or a similar method that lets me define filtering and use it repeatedly. I have a DF that i need to filter in to many smaller DF-s, Some of the filtering logic i need to reuse and change from time to time. I want to define the filtering logic so i can change it only in one place and then have it applied to all of the filtering i must do with it.
I would like to define the following filterings:
NB! I know the following is not hod to define a function. This is just to illustrate what i need.
Filter_A <- DF %>%
filter(between(EMTAK, 200, 232) |
between(EMTAK, 400, 450))
Filter_B <- DF %>%
filter(between(EMTAK, 250, 260) |
EMTAK == 500))
When i'm writing code i would like to re use the above filtering in a following way:
New_DF <- DF %>%
filter(EMTAK == Filter_A |
EMTAK == Filter_B,
SECTOR == "Metal" |
SECTOR == "Plastic")
In short i would like to define filtering and then use that filtering with other filterings to get the DF i need.
Could you please show me how do this :)
Thank you,