Filtering column in R
1
0
Entering edit mode
22 months ago
CH1374 ▴ 10

I'm still a beginner to R and trying to filter the AF column in this dataset to include values <=0.01 and the blank spaces.

sample of dataset

Have used the dplyr filter command to filter one of the other columns and that has been fine so I know it works just don't know how to apply it to the current command I want to run.

Below is what I'm running.

maf <- filter(maf.tb, maf.tb$"t_depth" >=20)
maf.2 <- filter(maf,maf$"AF" <=0.01 & "")

Any help would be really appreciated!

filter R • 659 views
ADD COMMENT
3
Entering edit mode
22 months ago
bkleiboeker ▴ 370

A few things...when you reference a column in a dataframe by name, you can'tuse quotation marks. Furthermore, when using dplyr functions, it assumes that you are using the dataframe you passed into the functions, so there's no need for the df$ before a column name. To filter the AF column in this dataset (unclear if dataset is called maf or maf.db so I'll assume the former) to include values <=0.01 and the blank spaces, try

maf.2 <- filter(maf,AF <= 0.01 | AF == "")

Which is equivalent to

maf.2 <- maf |> filter(AF <= 0.01 | AF == "")

if you want to practice using the pipe also!

ADD COMMENT

Login before adding your answer.

Traffic: 1529 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6