Lisann
Lisann

Reputation: 5855

R throw away rows on multiple conditions

I have a question about filtering in my dataset. My dataset look like this:

      PROJECT       FREQ
1       <NA>         NA
2       <NA>         NA
3       FSHD 0.01282051
4       <NA>         NA
5       <NA>         NA
6  GROEI,CMS 0.02564103
7       <NA>         NA
8      GROEI 0.00000132
9       <NA>         NA
10  NMD,BRCA 0.03846154

Here is my problem: I want to throw away all the rows that haven't in the PROJECT field: GROEI and in the FREQ field: bigger than 0.01.

I thought about something like this, but this isn't the way..

a1<-a[!(a$PROJECT != "GROEI" & a$FREQINHDB >= 0.02),]

Can anyone help me with this?

Thanks!

Upvotes: 0

Views: 1570

Answers (1)

Andrie
Andrie

Reputation: 179428

Since you want to match on a partial string, you can use grepl to match a regular expression with your data:

na.omit(a[!grepl("GROEI", a$PROJECT), ])
    n  PROJECT       FREQ
3   3     FSHD 0.01282051
10 10 NMD,BRCA 0.03846154

Upvotes: 3

Related Questions