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

Sarah Goslee sarah.goslee at gmail.com
Wed Jan 27 23:16:46 CET 2010


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 you an
unspecified potentially random order.

Sarah

On Wed, Jan 27, 2010 at 5:13 PM, lol zino <lolzino at gmail.com> wrote:
> Hello,
>
[...]
>
> I am attempting to merge them using the following:
>
> mergeddata <- merge(data1,data2, by.x="index", by.y="index2", sort=FALSE)
>
> I want to preserve the order of data1 by setting sort=FALSE, however
> the output I get is:
>
[...]
>
> which has not preserved the order of data1, and also does not have a
> clear relationship to the order of data2 that I can see. I also tried
> converting both index fields from chars to ints and got the same
> result. Any ideas of what is going on here?
>
> ______
-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list