Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subset data frame based on multiple conditions [duplicate]

People also ask

Can you subset multiple conditions in R?

Subsetting with multiple conditions in R, The filter() method in the dplyr package can be used to filter with many conditions in R.

How do you find duplicate rows in pandas based on multiple columns?

Find Duplicate Rows based on all columns To find & select the duplicate all rows based on all columns call the Daraframe. duplicate() without any subset argument. It will return a Boolean series with True at the place of each duplicated rows except their first occurrence (default value of keep argument is 'first').


Logic index:

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

Subset is your safest and easiest answer.

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

Real data example with mtcars

subset(mtcars, cyl==6 & am!=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, ]