Say I have some dataframe where I want to select items by one condition or another that’s a combination.
@rsubset df :x == 1 || :x == 2 :y == 3
With the data I’m working with, this returns matches of the 2nd clause and not the first. Is this possible, or do I have to just use filter
?
filter(d -> d.x == 1 || d.x == 2 && d.y == 3, df)
You are missing &&
in your condition, i.e.,
@rsubset df :x == 1 || :x == 2 :y == 3
# parses as
@rsubset(df, :x == 1 || :x == 2, :y == 3)
# which is the same as
@rsubset df ((:x == 1 || :x == 2) && :y == 3)
# as multiple conditions get combined via `and`
# In contrast
@rsubset df :x == 1 || :x == 2 && :y == 3
# parses as
@rsubset(df, (:x == 1 || (:x == 2 && :y == 3)))
# and gives the same result as
filter(d -> d.x == 1 || d.x == 2 && d.y == 3, df)
sigh Well, I feel stupid.