Hello guys,
I have some problems with the order function in R.What I am trying to do is to order by ("chr-name","chr-start","chr-end)
When I tried with the three it gave me just the two first columns, when I tried with only "chr-start", it worked but not as I wanted
Here is what I did and hopefully someone has an idea on how to do it
First try:
col=c("chr-nameRM","chr-startRM")
ordered1 <- chr_cancer [with(chr_cancer,order(col)),]
result:
chr-nameRM chr-startRM chr-endRM
chr1 839792 839815
chr1 859231 859271
second try:
ordered2 <- chr_cancer[order(chr_cancer[["chr-nameRM"]]),]
Result: This gave me half what I wanted as the chr names are not in order because what I am trying to do next is to compare other files.So if anyone has an idea I would be grateful
Thanks
1 answer
Untested, but something like this might work.
ordered = chr_cancer[order(chr_cancer[,"chr-nameRM"],chr_cancer[,"chr-startRM"],chr_cancer[,"chr-endRM"]),]
If you want to save yourself some headaches, don't use special characters (like -) in column names. Also, dplyr and data.table are your friends, so you might want to play with those in your free time to accomplish the same task.
Log in to answer this question.
Nobody would be able to answer this question without example data. And why do you use double brackets (
[["chr-nameRM"]])? If you're going to compare multiple tables maybe just simplesetkeyis all what you need.While I answered your "literal" question, can you elaborate on what you mean by "compare to other files"? How are you doing the comparison?
Hello, sorry for the late reply
Well I am using seqmonk as well and wanted to see if I come up with the same result files using R