[Rd] Re: [R] Unexpected behaviour of identical (PR#6799)
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Tue Apr 20 15:28:46 CEST 2004
Prof Brian Ripley <ripley at 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 at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-devel
mailing list