Filter table in R based on the number of chromosomes
Hi all,
I have a table like this:
CHROM POS N_ALLELES N_CHR M.F A.Freq
CM009840.1 932 2 14 0 1
CM009840.1 1096 2 84 0.357143 0.642857
CM009840.1 1107 2 32 0.84375 0.15625
CM009840.1 1177 2 74 0.445946 0.554054
CM009840.1 1276 2 64 0.640625 0.359375
CM009840.1 1295 2 68 0.632353 0.367647
CM009840.1 1471 2 48 0.770833 0.229167
CM009840.1 1518 2 52 0.192308 0.807692
CM009840.1 1527 2 48 0.875 0.125
I want to filter this table by the column N_CHR. The filter's basis is to remove rows smaller than 30.
for example: In the first row, there is number 14, So, i want to remove this row. And so for all the rows.
What is the best idea?
• 2,562 views
•
link
0 answers
No answers yet.
Log in to answer this question.
This is a pure, straightforward R question and might be closed. What have you tried?
I wrote some simple code but I could not solve this problem because my number of row is too much.
Did you try searching online? What is the simple code you wrote?
Yes I searched but I could not find the right script.
"I searched" does not help, my friend. What did you search for? Did you look for "remove rows that match a condition"? And searching seldom yields the exact script you need, it only gives you pointers you can use to get to where you need to go.
This should work if you have tidyverse loaded. Remember that if your aim is to remove rows that match condition X, you're looking to select rows that don't match condition X.
In fact, I want to remove the entire row from my table in those rows where my chromosome number is less than 30.
Is this right?
Try this:
myFilteredData <- myData[ myData$N_CHR > 30, ]Also, please invest some time to go through R tutorials. I am closing this post.Hello mostafarafiepour!
We believe that this post does not fit the main topic of this site.
This is a simple R question, not related to bioinformatics.
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!