From p.dalgaard at biostat.ku.dk  Tue Apr 20 15:28:46 2004
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Tue Apr 20 15:32:16 2004
Subject: [Rd] Re: [R] Unexpected behaviour of identical (PR#6799)
In-Reply-To: <Pine.LNX.4.44.0404201249140.11664-100000@gannet.stats>
References: <Pine.LNX.4.44.0404201249140.11664-100000@gannet.stats>
Message-ID: <x2y8oq4w35.fsf@biostat.ku.dk>

Prof Brian Ripley <ripley@stats.ox.ac.uk> writes:

> 
> No, it comes from
> 
> > get("[.factor")
> function (x, i, drop = FALSE)
> {
>     y <- NextMethod("[")
>     class(y) <- oldClass(x)
>     attr(y, "contrasts") <- attr(x, "contrasts")
>     attr(y, "levels") <- attr(x, "levels")
>     if (drop)
>         factor(y)
>     else y
> }
> 
> > attributes(af[1:2, drop=TRUE])
> $levels
> [1] "A" "B"
> 
> $class
> [1] "factor"
> 
> > attributes(af[1:2, drop=FALSE])
> $class
> [1] "factor"
> 
> $levels
> [1] "A" "B"
> 
> and one needs to swap the orders.  I am about to commit the change.

I got to about the same spot and started thinking about methods
for putting attributes back in the same order that they were found, as
in

A <- attributes(x)
attributes(y) <- A[names(A) %in% c("class","contrasts","levels")]

Just swapping the order is probably fine, though.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907


[Rd] Re: [R] Unexpected behaviour of identical (PR#6799)
Peter Dalgaard