0

How can I avoid chaining OR conditions with | like this:

small_town_villages = data_ger[which(data_ger$type_city==1|data_ger$type_city==2 |data_ger$type_city==3),]

city = data_ger[~(small_town_villages),]

Is their a way of doing this more concisely? Furthermore, I think there is an error in my last line.

Leo Pfeiffer
  • 76
  • 1
  • 5

1 Answers1

0

Try %in%:

small_town_villages = data_ger[data_ger$type_city %in% c(1:3),] 

or !x %in% y if you want the list of not included values.

gaut
  • 5,771
  • 1
  • 14
  • 45