r - sorting set of data.frame by paired-row? -


this question has answer here:

i have 3 data.frame objects, did combine them , remove duplicated instances, seems order not enough, want sort them in natural order. how can make happen more efficiently?

toy data

foo <- data.frame( start=seq(1, by=4, len=6), stop=seq(3, by=4, len=6)) bar <- data.frame(start=seq(5, by=2, len=7), stop=seq(7, by=2, len=7)) bleh <- data.frame(start=seq(1, by=5, len=5), stop=seq(3, by=5, len=5)) 

i did combine them follows:

out <- rbind.data.frame(foo, bar, bleh) out <- out[!duplicated(out),] 

but out doesn't have right order, want sort them in correct order row.

desired output: (manually pin out)

       start  stop 1      1      3 2      5      7 3      6      8 4      7      9 5      9      11 6      11     13 7      13     15 8      15     17 9      16     18 10     17     19 11     21     23 

how can desired output format? lot

we can use order do.call

out1 <- out[do.call(order, out),] out1 #    start stop #1      1    3 #2      5    7 #15     6    8 #8      7    9 #3      9   11 #10    11   13 #4     13   15 #12    15   17 #17    16   18 #5     17   19 #6     21   23  rownames(out1) <- null 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -