Question: (Closed) Filtering the data frame
0
gravatar for challagandla.anil
7 months ago by
challagandla.anil10 wrote:

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 • 223 views
ADD COMMENTlink modified 7 months ago by Benn6.5k • written 7 months ago by challagandla.anil10

Please show us what you tried

ADD REPLYlink written 7 months ago by WouterDeCoster38k

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!

ADD REPLYlink written 7 months ago by RamRS21k
0
gravatar for Benn
7 months ago by
Benn6.5k
Netherlands
Benn6.5k wrote:

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)
ADD COMMENTlink written 7 months ago by Benn6.5k

> 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()
ADD REPLYlink modified 7 months ago • written 7 months ago by cpad011211k
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2014 users visited in the last hour