Re: [R] Merge sort

2016-04-20 Thread Duncan Murdoch
On 20/04/2016 7:38 AM, Gaston wrote: I indeed used is.na() to check length, as I was not sure weather lenght() was a simple query or would go through the whole vector to count the elements. length() is a simple query, and is very fast. The other problem in your approach (which may not be a

Re: [R] Merge sort

2016-04-20 Thread Gaston
I indeed used is.na() to check length, as I was not sure weather lenght() was a simple query or would go through the whole vector to count the elements. So to sum up, function calls are expensive, therefore recursion should be avoided, and growing the size of a vector (which is probably

Re: [R] Merge sort

2016-04-19 Thread Duncan Murdoch
On 19/04/2016 3:39 PM, Gaston wrote: Hello everyone, I am learning R since recently, and as a small exercise I wanted to write a recursive mergesort. I was extremely surprised to discover that my sorting, although operational, is deeply inefficient in time. Here is my code : merge <-

[R] Merge sort

2016-04-19 Thread Gaston
Hello everyone, I am learning R since recently, and as a small exercise I wanted to write a recursive mergesort. I was extremely surprised to discover that my sorting, although operational, is deeply inefficient in time. Here is my code : > merge <- function(x,y){ > if (is.na(x[1]))

Re: [R] Merge: sort=F not preserving order?

2010-01-28 Thread Bart Joosen
You could add an extra sequence on the dataframe you wish to sort on. Merge together, sort by the sequence, delete the sequence. It's a bit more work, but it will give you what you want. Bart -- View this message in context:

[R] Merge: sort=F not preserving order?

2010-01-27 Thread lol zino
Hello, I have the following data1 (index are chars):     index 1  008823 2  012689 3  004503 4  002991 5  012689 6  002845 7  012689 8  012395 9  012689 10 009302 11 002845 12 006669 13 008823 14 009302 15 025340 16 012689 and data2 in this format (index2 are chars):        index2      tic 1  

Re: [R] Merge: sort=F not preserving order?

2010-01-27 Thread Sarah Goslee
Why yes. If you keep reading the helpfile for merge, you come to this bit: Value: A data frame. The rows are by default lexicographically sorted on the common columns, but for ‘sort = FALSE’ are in an unspecified order. sort=FALSE doesn't preserve your order; instead it gives