0 votes
1 view
in R Programming by (5.3k points)

enter image description here

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

1 Answer

0 votes
by (25.3k points)

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

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...