Skip to content
Back to formatted view

Raw Message

Message-ID: <1302137195779-3432250.post@n4.nabble.com>
Date: 2011-04-07T00:46:35Z
From: Brad Patrick Schneid
Subject: unexpected sort order with merge
In-Reply-To: <u1ooc4jxov5.fsf@lx-chrateresearch01.citadelgroup.com>

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.