From savicky at cs.cas.cz  Mon May 25 12:27:17 2009
From: savicky at cs.cas.cz (Petr Savicky)
Date: Mon, 25 May 2009 12:27:17 +0200
Subject: [Rd] inconsistency in ?factor
In-Reply-To: <20090525155806.52c19122@absentia>
References: <20090525070414.GA9602@cs.cas.cz>
	<20090525155806.52c19122@absentia>
Message-ID: <20090525102717.GA30112@cs.cas.cz>

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.



[Rd] inconsistency in ?factor
Petr Savicky