Gabor Grothendieck wrote:
And one other point.

z <- zoo(1:4)
.gt(z, 1, 2)

fails because z[1] and z[2] are at different time points so

   z[1] == z[2]

is logical(0) because when zoo compares objects it aligns them
first.

Yes, that was the point that I was trying to make. Well, arguably it doesn't "fail", it just does what it is supposed to do. Things would "work" with [[ or a preceding unclass(z), but that would break comparisons involving, say, POSIXlt objects. So you're sort of stuck between a rock and a hard place.


On Wed, Oct 22, 2008 at 2:19 PM, Gabor Grothendieck
<[EMAIL PROTECTED]> wrote:
Yes, I noticed that but rank is not generic.  An xtfrm.zoo
method has been added to zoo on R-Forge but rank still
fails:

R.version.string
[1] "R version 2.8.0 Patched (2008-10-21 r46766)"
packageDescription("zoo")$Version
[1] "1.5-3"
library(zoo)
# next line adds xtfrm zoo method
xtfrm.zoo <- coredata
z <- zoo(1:4)
order(z) # ok
[1] 1 2 3 4
qqnorm(z) # ok
rank(z) # error
Error in if (xi == xj) 0L else if (xi > xj) 1L else -1L :
 argument is of length zero


(If the MIME type is wrong, then that will happen.)

Anyways, the root cause seems to be the new function .gt() which is
related to

   o   New generic function xtfrm() as an auxiliary helper for
       sort(), order() and rank().  This should return a numeric
       vector that sorts in the same way as its input.  The default
       method supports any class with ==, > and is.na() methods but
       specific methods can be much faster.

       As a side-effect, rank() will now work better on classed
       objects, although possibly rather slowly.

Here, "better" may be in the eyes of the beholder, for


dax[3]==dax[6]

Data:
logical(0)

Index:
integer(0)

and accordingly


rank(dax)

Error in if (xi == xj) 0L else if (xi > xj) 1L else -1L :
 argument is of length zero

which is the error that you are seeing.

What to do about it is a bit dubious. Obviously, we don't want to "fix"
.gt() so that it automatically unclasses objects, and I assume that zoo
has its reasons for not wanting to compare series with different
indices. So I suppose that either the user must unclass, or zoo define
rank.zoo.

Actually qqnorm does not use rank but it does use order and with the
xtfrm.zoo method I mentioned qqnorm works with zoo; however, I think
rank needs to be fixed in R to make use of xtfrm as well since I would have
expected that supplying an xtfrm method for zoo would be sufficient to
get both order and rank to work without giving errors.  Also note that rank
is not generic.

Notice that xtfrm.default() uses rank()....

--
  O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
 c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED])              FAX: (+45) 35327907





--
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED])              FAX: (+45) 35327907

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to