problem with order function
1
0
Entering edit mode
9.6 years ago
yasjas ▴ 70

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

R • 1.8k views
ADD COMMENT
2
Entering edit mode

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 simple setkey is all what you need.

ADD REPLY
1
Entering edit mode

While I answered your "literal" question, can you elaborate on what you mean by "compare to other files"? How are you doing the comparison?

ADD REPLY
0
Entering edit mode

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

ADD REPLY
1
Entering edit mode
9.6 years ago

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.

ADD COMMENT

Login before adding your answer.

Traffic: 1887 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6