Question: insert word in each row
0
gravatar for yasjas
4.6 years ago by
yasjas70
United Kingdom
yasjas70 wrote:

Hello,

I have this dataframe

chrname     start       end
1       X  99883667  99894988
2       X  99839799  99854882
3      20  49551404  49575092
4       1 169818772 169863408
5       1 169631245 169823221
6       1  27938575  27961788

and I would like to add in the first column chrname a word "chr" before each word 

chrname     start       end
1    chr X  99883667  99894988
2    chrX  99839799  99854882
3    chr  20  49551404  49575092
4    chr 1 169818772 169863408
5    chr  1 169631245 169823221
6     chr 1  27938575  27961788

I tried with paste and assign but no result?any help please?

ADD COMMENTlink modified 4.6 years ago by Deepak Tanwar4.0k • written 4.6 years ago by yasjas70
4
gravatar for Beuss
4.6 years ago by
Beuss110
France
Beuss110 wrote:

Let say your dataframe is "d"

d$chrname<-paste("chr", d$chrname, sep="")

 

ADD COMMENTlink modified 4.6 years ago • written 4.6 years ago by Beuss110
3
gravatar for wpwupingwp
4.6 years ago by
wpwupingwp110
China
wpwupingwp110 wrote:

you said before each word, but your result show that some of them have extra blank but others not

 

ADD COMMENTlink written 4.6 years ago by wpwupingwp110

I think he just want to append 'chr' to each chromosome as few tools expects data that way.

ADD REPLYlink written 4.6 years ago by geek_y10.0k
1

awk -F '\t' '{$2=chr$2;print $0}' filename

didn't test that :)

ADD REPLYlink written 4.6 years ago by wpwupingwp110
3
gravatar for michael.ante
4.6 years ago by
michael.ante3.5k
Austria/Vienna
michael.ante3.5k wrote:
Let d be your dataframe.
d_new=data.frame(chrname=paste(rep("chr",dim(d)[1]),d$chrname,sep=""),start=d$start,stop=d$stop)

Should do the job.

ADD COMMENTlink modified 4.6 years ago • written 4.6 years ago by michael.ante3.5k
1
gravatar for Deepak Tanwar
4.6 years ago by
Deepak Tanwar4.0k
ETH Zürich, Switzerland
Deepak Tanwar4.0k wrote:

These are very basic steps with R. Please go through the R documentation http://cran.r-project.org/manuals.html

These will help you a lot.

Also, always use "Tab" key while working with the function, which will let you know the parameters you could provide.

or 

?function_name

ADD COMMENTlink modified 4.6 years ago • written 4.6 years ago by Deepak Tanwar4.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: 2209 users visited in the last hour