Re: [R] unexpected sort order with merge

From: B77S <bps0002_at_auburn.edu>
Date: Wed, 06 Apr 2011 17:46:35 -0700 (PDT)

That is odd, I noticed some weird sorting with merge() a while back too and always am careful with it now. Fortunately, sort=FALSE seems to work the way one would think most of the time.

Although, the following results seem weird too! (adding by="date" makes it not sort oddly, regardless of sort=TRUE or FALSE)

> merge(d1, d2, by="date", sort=F)

      date icpn.x foo icpn.y bar
1 Jan 2000 500 1 500 10
2 Feb 2000 500 2 500 20
3 Mar 2000 500 3 500 30
4 Apr 2000 500 4 500 40
5 May 2000 500 5 500 50
6 Jun 2000 500 6 500 60
> merge(d1, d2, by="date", sort=T)

      date icpn.x foo icpn.y bar
1 Jan 2000 500 1 500 10
2 Feb 2000 500 2 500 20
3 Mar 2000 500 3 500 30
4 Apr 2000 500 4 500 40
5 May 2000 500 5 500 50
6 Jun 2000 500 6 500 60
> merge(d1, d2, by="date")

      date icpn.x foo icpn.y bar
1 Jan 2000 500 1 500 10
2 Feb 2000 500 2 500 20
3 Mar 2000 500 3 500 30
4 Apr 2000 500 4 500 40
5 May 2000 500 5 500 50
6 Jun 2000 500 6 500 60
> merge(d1, d2)

      date icpn foo bar
1 Apr 2000 500 4 40
2 Feb 2000 500 2 20
3 Jan 2000 500 1 10
4 Jun 2000 500 6 60
5 Mar 2000 500 3 30
6 May 2000 500 5 50

--
View this message in context: http://r.789695.n4.nabble.com/unexpected-sort-order-with-merge-tp3431338p3432250.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 07 Apr 2011 - 00:58:13 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 07 Apr 2011 - 13:50:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive