Dataframe:
A ; B
x 1
x 7
y 2
y 3
z 9
z 1
I want to remove all rows where A=x and A=z because x and z have value 1 in column B. Therefore, the dataframe must look like this:
A ; B
y 2
y 3
Thanks,
Dataframe:
A ; B
x 1
x 7
y 2
y 3
z 9
z 1
I want to remove all rows where A=x and A=z because x and z have value 1 in column B. Therefore, the dataframe must look like this:
A ; B
y 2
y 3
Thanks,
You can try subset
> subset(df, ! A %in% c("x","z"))
A B
3 y 0
4 y 0
data
> dput(df)
structure(list(A = c("x", "x", "y", "y", "z", "z"), B = c(1L,
0L, 0L, 0L, 0L, 1L)), class = "data.frame", row.names = c(NA,
-6L))
my.data.frame <- subset(data , A != "x" | A != "z")
Btw, duplicate of How to combine multiple conditions to subset a data-frame using "OR"?
a data.table
approach
library( data.table )
DT <- fread("A B
x 1
x 7
y 2
y 3
z 9
z 1")
DT[ copy(DT)[, temp := sum(B == 1), by = A ]$temp == 0, ]
# A B
# 1: y 2
# 2: y 3