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

Dear All, I have a data frame (RNA-Seq), I want to filter a column (>=1.5 & <=-2, log2 values), should be able to delete all the rows with respective the column values which falls in the specified range using R (dpylr package I tried). Kindly help me how to do it, consider I am very new for R. Thank you

rna-seq

Hello challagandla.anil!

We believe that this post does not fit the main topic of this site.

Pure R question, please search StackOverflow

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

1 answer

You don't need dplyr, but subset will do, Let's say you want all the values in column X1 that are higher than 1.5 or lower than -2.

df <- data.frame(replicate(10,sample(-3:3,10,rep=TRUE)))

df
   X1 X2 X3 X4 X5 X6 X7 X8 X9 X10
1   0 -1 -2 -3  1 -3 -3  3 -1  -1
2   3 -2  2  1  0  2  2  0 -1   0
3   1 -2 -2 -2  2 -3 -2  0 -2   0
4  -1 -3  0 -1  1 -3  2 -3  0  -3
5   1  3 -2  3 -3 -3 -3  3  1   0
6   0 -2  2  2  0  2 -3  1  1   1
7  -3  0 -1 -2 -2  2  2  2  1   3
8  -1 -1 -1 -3  2 -3  0 -1 -1   1
9  -3  3  3 -3  0  0 -2 -3  2   3
10  0 -3  3  1  3 -3 -2 -1  1  -3

subset(df, df$X1 > 1.5 | df$X1 < -2)

> subset(df, X1 >= 1.5 | X1 <= -2) also works. If you are trying dplyr, for the above data frame, use following code:

library(dplyr)
df %>% filter (X1 >= 1.5 | X1 <= -2)

However, with dplyr, one of the issues is that you would loose row index (row names), to retain row index/row names, use following code:

library(dplyr)
library(tibble)
df %>% 
  rownames_to_column() %>% 
  filter (X1 >= 1.5 | X1 <= -2) %>% 
  column_to_rownames()

Log in to answer this question.