This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Filtering column in R

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

1 answer

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!

Log in to answer this question.