0

I have a very simple question, but would appreciate advice!

I am trying to run the following dplyr operation to remove rows for 3 states from a dataset containing data by state.

new_data <- old_data %>% filter(state!="NC", state!="AL", state!="AR")

The above command works. But, I am wondering if there is a way to remove the 3 states more simply, without retyping the state!= bit three times.

For example, maybe I could do something like:

new_data <- old_data %>% filter(state!= ("NC" |"AL" |"AR"))

However, this did not work. Your advice appreciated! Thanks!

2
  • 1
    You can try ... !(state %in% c("NC", "AL", "AR")) Commented Jul 9, 2020 at 18:41
  • 1
    @markus Thanks! That worked for me! Commented Jul 9, 2020 at 18:43

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.