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

Login

0 votes

To conditionally remove data frame rows, you can use the following code:

A <- c('A','B','A','B','A')

> B <- c('C','D','C','D','C')

> C <- c('E','F','E','F','E')

> D <- c('G','H','G','H','G')

> E <- c(1,0,1,0,1)

> d <- data.frame(A, B, C, D, E)

> d

A B C D E

1 A C E G 1

2 B D F H 0

3 A C E G 1

4 B D F H 0

5 A C E G 1

According to your condition:

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

> d

A B C D E

1 A C E G 1

3 A C E G 1

5 A C E G 1