Question: Delete numbers in the tables column
1
gravatar for mostafarafiepour
2.2 years ago by
mostafarafiepour80 wrote:

Hi All,

I have a table with six columns (in the following).

enter image description here

So, I want to delete SNPs that are less than number 10 in the SNP column.

What is the best idea?

Best Regard

Mostafa

R • 794 views
ADD COMMENTlink modified 2.2 years ago by Prakash2.0k • written 2.2 years ago by mostafarafiepour80

You can filter out these rows :

https://stackoverflow.com/questions/7381455/filtering-a-data-frame-by-values-in-a-column

ADD REPLYlink modified 2.2 years ago • written 2.2 years ago by Bastien HervĂ©4.9k
6
gravatar for lieven.sterck
2.2 years ago by
lieven.sterck9.0k
VIB, Ghent, Belgium
lieven.sterck9.0k wrote:

awk !

a cmdline such as below one should do the trick:

awk ' $4 >= 10' <table-file> > new_file

and if you want to (additionally) apply calculations on a certain column:

awk ' $4 >= 10' <table-file> | awk '$2=$2+2000' > new_file
ADD COMMENTlink modified 2.2 years ago • written 2.2 years ago by lieven.sterck9.0k
5
gravatar for Prakash
2.2 years ago by
Prakash2.0k
India
Prakash2.0k wrote:

Read the file, and filter out any row where SNP column is more than or equal to 10:

data <- read.table("SNP.txt", header = TRUE)
data <- data[ data$SNP >= 10, ])

To exclude 1st BP column, and to add 20KB to BP column:

data <- data[ , -3 ]
data$BP <- data$BP + 20000
ADD COMMENTlink modified 2.2 years ago by zx87549.7k • written 2.2 years ago by Prakash2.0k

many thanks for your reply,

I could do it.

Now, I have two BP columns.

First I want to delete one of them. And the second, I want to add 20,000 to each of the numbers in the first BP column.

What is the best idea?

ADD REPLYlink written 2.2 years ago by mostafarafiepour80

awk again ;)

pretty nifty stuff awk

ADD REPLYlink written 2.2 years ago by lieven.sterck9.0k

yes, now i want to add amount 20,000 to each of the numbers in the first BP column.

for example:

1+20000
20001+20000
40001+20000
.
.
.
ADD REPLYlink modified 2.2 years ago by _r_am30k • written 2.2 years ago by mostafarafiepour80
1

You can add other operations to the cmdline I provided earlier (or do it in one go even). I'll split it up in separate operations for increased readability and understanding

awk ' $4 >= 10' <table-file> | awk '$2=$2+2000' > new_file
ADD REPLYlink modified 2.2 years ago • written 2.2 years ago by lieven.sterck9.0k

See edit, answer updated.

ADD REPLYlink modified 2.2 years ago by zx87549.7k • written 2.2 years ago by Prakash2.0k

why fire up R while you can simply do this command line? ;-)

ADD REPLYlink written 2.2 years ago by lieven.sterck9.0k
1

Maybe because some are more comfortable in R world. Please add your comments regarding +20KB, to your answer, so that your answer is complete.

ADD REPLYlink written 2.2 years ago by zx87549.7k

OK, added it (though the question on the +20K was part of this thread).

and, OK, point taken.

ADD REPLYlink written 2.2 years ago by lieven.sterck9.0k
Please log in to add an answer.

Help
Access

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