[Rd] inconsistency in ?factor

Petr Savicky savicky at cs.cas.cz
Mon May 25 12:27:17 CEST 2009


On Mon, May 25, 2009 at 03:58:06PM +0800, Berwin A Turlach wrote:
> Well, the first statement is a remark on comparison in general while
> the second statement is specific to "comparison operators and generic
> methods".  There are other ways of comparing objects; note:
> 
> R> f1 <- factor(c("a", "b", "c", "c", "b", "a"), levels=c("a", "b", "c"))
> R> f2 <- factor(c("a", "b", "c", "c", "b", "a"), levels=c("c", "b", "a"))
> R> f1==f2
> [1] TRUE TRUE TRUE TRUE TRUE TRUE
> R> identical(f1,f2)
> [1] FALSE
> R> all.equal(f1,f2)
> [1] "Attributes: < Component 2: 2 string mismatches >"

I see. We have to distinguish comparison of the objects and their components.

Let me propose the following formulation
  Two factors may be identical only if they have the same set of
  levels (in the same order).
instead of
  Be careful only to compare factors with the same set of
  levels (in the same order).

Petr.



More information about the R-devel mailing list