Reputation: 87
I need to remove rows in my data which satisfy more than one condition
the variables are
comorbidity
date_of_comorbidity
date_of_birth
i want to remove the rows where both comorbidity is equal to 10 AND date of comorbidity is less than date of birth
I have tried
newdata<-subset(df, !(comorbidity1==10 & date_of_comorbidity<date_of_birth))
This seems to remove the observations when it is one or the other
I need it to be only when both of these criteria occur in the same row.
Upvotes: 1
Views: 118
Reputation: 15
A similar solution with dplyr is:
library(dplyr)
newdata <- df %>% filter(comorbidity1 !=10 & date_of_comorbidity >= date_of_birth)
Upvotes: 0
Reputation: 176
Try
newdata<-subset(df, comorbidity1 !=10 | date_of_comorbidity >= date_of_birth)
Upvotes: 1