I am looking for an dplyr equivalent on
SELECT user_id, item
FROM users
WHERE user_id NOT IN (1, 5, 6, 7, 11, 17, 18); -- admin accounts
I can use
users %>% filter(user_id != 1) but can't imagine using multiple && all the way.
Is there a way to exclude a number of rows?
You can use ! and %in%:
filtered_users <- filter(users, !user_id %in% c(1, 5, 6, 7, 11, 17, 18))
This is based on https://stackoverflow.com/a/34444336/1152809. I just googled "dplyr not in" and this was the first result. Google is your friend when learning new things. Also, as @thelatemail said, %in% is a base R function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With