Reputation: 563
I have a dataset with multiple columns. I want to take out rows from the set which meet two conditions.
I thought this would work:
CarS <- CarS[ CarS$CylCode !=17 && CarS$ECode !=191,]
But this is taking out all rows that meet either condition, and I want both conditions to be met in order for that row to be removed?
Thanks!
Upvotes: 0
Views: 81
Reputation: 338
You could try using sqldf, although this will not be the the most elegant answer:
library("sqldf")
CarS<-sqldf('
select *
from CarS
where
(CylCode <> 17 and
ECode <> 191 )
')
Second approach
CarS[setdiff(rownames(CarS),rownames(toremove )),]
toremove <-sqldf('
select *
from CarS
where CylCode = 17 and ECode = 191 ')
Upvotes: 1