insert word in each row
4
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?
assign
r
paste
• 2.4k views
•
link
updated 2.5 years ago by
Ram
44k
•
written 9.7 years ago by
yasjas
▴
70
Let say your dataframe is d
d$chrname<-paste("chr", d$chrname, sep="")
•
link
updated 2.5 years ago by
Ram
44k
•
written 9.7 years ago by
Beuss
▴
140
You said before each word, but your result show that some of them have extra blank but others not
•
link
updated 2.5 years ago by
Ram
44k
•
written 9.7 years ago by
wpwupingwp
▴
120
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.
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
Login before adding your answer.
Traffic: 1838 users visited in the last hour
I think he just want to append 'chr' to each chromosome as few tools expects data that way.
Didn't test that :)