jeudi 16 juin 2016

How do I filter a data frame with dplyr's filter() and R-base's ifelse()?

My data frame df looks something like this:

Home,     Away,    Inning
"Boston", "NYC",    "Top"
"NYC",    "Boston", "Bottom"
"NYC",    "Boston", "Top"

I want to use dplyr's filter() to make a data frame that gets its data from an ifelse() query.

If Home is "Boston", give me all rows where Inning is "Top". If Away is "Boston", give me all rows where Inning is "Bottom".

How do I do this with dplyr's filter()?

Aucun commentaire:

Enregistrer un commentaire