Filtering multiple domains in R and using not operator

I am a new user to R. I tried to filter multiple objects with conditions but got an error. Data set is Hotel Bookings assigned as Bookings.

bookings %>% 
  filter((arrival_date_year ==2015 | arrival_date_year ==2016) & (arrival_date_month =="June")) %>%   
  filter %!in% (reservation_status == ("Canceled"))

I even tried it in a line. I wanted to use the not operator but it didnt work.

bookings %>% 
  filter((arrival_date_year ==2015 | arrival_date_year ==2016)& (arrival_date_month =="June")& reservation_status== !("Canceled")) 

But here i am unable to apply the not operator correctly. It showed error. Please tell my mistake.
It showed
Error in filter():
! Problem while computing ..1 = ... & reservation_status == (!("Canceled")).

I can't be sure because you haven't provided a reproducible example (I don't know from where the Hotel Bookings data frame comes from), but I think this is what you want to do.

bookings %>% 
    filter((arrival_date_year == 2015 | arrival_date_year == 2016),
           arrival_date_month == "June",
           reservation_status != "Canceled")

If this doesn't solve your problem, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

1 Like

It worked. Thanks a lot.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.