From Waclaw.Marcin.Kusnierczyk at idi.ntnu.no  Tue Mar 17 11:57:14 2009
From: Waclaw.Marcin.Kusnierczyk at idi.ntnu.no (Wacek Kusnierczyk)
Date: Tue, 17 Mar 2009 11:57:14 +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: <49BF820A.908@idi.ntnu.no>

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
>   

as a corollary, the warning printed when comparing elements of a factor
is misleading:

    f = factor(1:2)
    f[1] < f[2]
    # [1] NA
    # Warning message:
    # In Ops.factor(f[1], f[2]) : < not meaningful for factors

    g = as.ordered(f)
    is.factor(g)
    # TRUE
    g[1] < g[2]
    # TRUE


< *is* meaningful for factors, though not for unordered ones.  the
warning is generated in Ops.factor, src/library/base/all.R:7162, and
with my limited knowledge of the r internals i can't judge how easy it
is to fix the problem.

vQ



[Rd] Match .3 in a sequence
Wacek Kusnierczyk