Reputation: 47
I have a dataframe with thousands of observations, and a few variables. I want to create a subset of this dataframe whereby I remove rows of no interest to me, based upon multiple conditions working in union.
For example if I wanted to perform the following:
Remove entries where event_type = 'A' or 'T' and value < 0,
how would one format this in R? (Where event_type and value are variables) Many thanks.
Upvotes: 2
Views: 460
Reputation: 886938
In base R
, use subset
subset(df1, event_type %in% c("A", "T") & value < 0)
Upvotes: 2
Reputation: 1928
Here's a dplyr response. Simply filter
the data for the conditions indicated and the result should be what you're looking for.
library(dplyr)
df_filtered <- df %>%
filter(event_type %in% c('A', 'T'),
value < 0)
Upvotes: 2