[r] Conditionally Remove Dataframe Rows with R

enter image description here

Using R, how can I write the following logic into the dataframe: IF column A = B and Column E = 0, delete row

This question is related to r

The answer is


Logic index:

d<-d[!(d$A=="B" & d$E==0),]

Use the which function:

A <- c('a','a','b','b','b')
B <- c(1,0,1,1,0)
d <- data.frame(A, B)

r <- with(d, which(B==0, arr.ind=TRUE))
newd <- d[-r, ]

Subset is your safest and easiest answer.

subset(dataframe, A==B & E!=0)

Real data example with mtcars

subset(mtcars, cyl==6 & am!=0)