DDRRpy DDRRpy - 3 months ago 17
R Question

filtering a data frame in R

I wish to filter a dataframe shown in table 1 so it looks like table 2 by removing any rows containing "Pathogenic" in the class column and 0 in the validated column. Although, I am unsure which tool I should use to accomplish this.

Table1

Class Validated
Pathogenic 1
Pathogenic 1
Pathogenic 0
Pathogenic 0
Likely Pathogenic 1
Likely Pathogenic 0
Likely Pathogenic 1
Uncertain 0
Uncertain 1


Table2

Class Validated
Pathogenic 1
Pathogenic 1
Likely Pathogenic 1
Likely Pathogenic 0
Likely Pathogenic 1
Uncertain 0
Uncertain 1

Answer

Assuming that the type of your "Validated" column is numeric:

table2 <- table1[!(table1$Class == "Pathogenic" & table1$Validated == 0),]