[Rd] Match .3 in a sequence

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Tue Mar 17 11:57:14 CET 2009


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



More information about the R-devel mailing list