[R] puzzled by math on date-time objects

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Tue Mar 10 23:27:27 CET 2009

Stavros Macrakis wrote:
> It does seem sensible that median and quantile would work for the
> POSIXct, Date, and other classes for which they are logically
> well-defined, but strangely enough, they do not (except for odd-length
> input).  The summary function has a special case (summary.POSIXct)
> which does the straightforward, obvious thing here.  I do not
> understand why this is not done by median and quantile themselves.
> Conversely, for the complex class, median and quantile do not give an
> error but instead produce meaningless results

median, but not quantile, seems to fail on complex:

    # error, needs numeric
    # fine

the latter is a presumably a bug, because it doesn't follow the
documentation, ?quantile:

     quantile(x, ...)


       x: numeric vectors whose sample quantiles are wanted.  Missing
          values are ignored.

and complex is not numeric:

    # FALSE

> since the complexes do
> not form an ordered field).

well, in r complexes are not comparable, but they can be sorted:

    0i < 1i
    # no go
    sort(c(0i, 1i))
    # fine


More information about the R-help mailing list