mrquad mrquad - 1 year ago 102
R Question

Querying a dataframe in R

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
and the Country is

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

I would appreciate your replies!

Answer Source

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")), ]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download