From savicky at cs.cas.cz  Tue Mar 17 11:10:28 2009
From: savicky at cs.cas.cz (Petr Savicky)
Date: Tue, 17 Mar 2009 11:10:28 +0100
Subject: [Rd] Match .3 in a sequence
In-Reply-To: <49BF6A3B.1080200@idi.ntnu.no>
References: <48f8cced0903160636k112500f6k4b8d46c1ac775d89@mail.gmail.com>
	<8b356f880903160824q4fb9068br1f22601064a8042d@mail.gmail.com>
	<48f8cced0903161553u7969905ck69e7ebd7831f1f3a@mail.gmail.com>
	<8b356f880903161639q29e8bf4eh29624516bf8aa783@mail.gmail.com>
	<20090317060749.GA24730@cs.cas.cz> <49BF6A3B.1080200@idi.ntnu.no>
Message-ID: <20090317101028.GA17676@cs.cas.cz>

On Tue, Mar 17, 2009 at 10:15:39AM +0100, Wacek Kusnierczyk wrote:
...
> there's one more curiosity about factors, in particular, ordered factors:
> 
>     ord <- as.ordered(nums); ord
>     # [1] 0.300000000000000 0.3               0.3              
> 0.300000000000000
>     # Levels: 0.300000000000000 < 0.3 < 0.3 < 0.300000000000000
> 
>     ord[1] < ord[4]
>     # TRUE
>     ord[1] == ord[4]
>     # TRUE
...

The following workaround should help in most cases.

  nums <- (.3 + 2e-16 * c(-2,-1,1,2))
  nums # [1] 0.3 0.3 0.3 0.3
  nums <- signif(nums, digits=15)
  as.ordered(nums) # Levels: 0.3
  as.factor(nums) # Levels: 0.3

Petr.



[Rd] Match .3 in a sequence
Petr Savicky