-2

I have a dataframe which has a 3 fields: NAME, CATEGORY, COUNTRY

Now I would like to have all data where the category is the String over 10 mio or the Country is Germany and the Country is Sweden.

Any recommendation how to "query" my dataFrame in R?

I would appreciate your replies!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Carol.Kar
  • 4,581
  • 36
  • 131
  • 264

1 Answers1

2

You can use which.

desireDf <- df[ which( df$CATEGORY=="over 10 mio" &  (df$COUNTRY=="Germany" | df$COUNTRY=="Sweden" )), ]

Also it works without which:

desireDf <- df[ (df$CATEGORY=="over 10 mio" &  (df$COUNTRY=="Germany" | df$COUNTRY=="Sweden")), ]
Fedorenko Kristina
  • 2,607
  • 2
  • 19
  • 18