[R] <NA> from cut.Date

Benjamin Tyner btyner at gmail.com
Wed Sep 17 23:57:03 CEST 2014


Thanks Brian! 

The confusion was due to my failure to notice that these two functions have opposite defaults for 'right':

   > args(cut.default)
   function (x, breaks, labels = NULL, include.lowest = FALSE, right = TRUE, dig.lab = 3L, ordered_result = FALSE, ...) 

   > args(cut.Date)
   function (x, breaks, labels = NULL, start.on.monday = TRUE, right = FALSE, ...) 

I suppose the latter does make sense, given that days, months, years etc are right-continuous functions of time.

Regards
Ben

> On 17/09/2014 12:04, Benjamin Tyner wrote:
> >/ Hello,
> />/
> />/ I'm wondering if this is expected?
> /
> It is as documented!
> >/
> />/      > cut(structure(11111, class="Date"), structure(c(11100,11111),
> />/ class="Date"))
> />/      [1] <NA>
> />/      Levels: 2000-05-23
> />/
> />/ The help page says that "for ‘"Date"’ objects, only ‘"day"’, ‘"week"’,
> />/ ‘"month"’, ‘"quarter"’ and ‘"year"’ are allowed" [for the 'breaks'
> />/ argument]. Though I am not sure whether this statement is only
> />/ applicable in the context of the previous sentence about interval
> />/ specification (i.e., a roundabout way of saying that ‘"sec"’, ‘"min"’,
> />/ ‘"hour"’, and ‘"DSTday"’ are not allowed for 'Date' objects), or whether
> />/ it also means that a vector of cut points (as in my example) is likewise
> />/ not allowed? If the latter, then perhaps the function out to error out
> />/ rather than return <NA> in this case?
> /
> The NA is correct: the value you pass is not covered by the 'breaks' you 
> specified.  As the help says
>
>       Using both ‘right = TRUE’ and ‘include.lowest = TRUE’ will include
>       both ends of the range of dates.
>
> With the default values, only the lower end is included.
>
> -- 
> Brian D. Ripley,                  ripley at stats.ox.ac.uk <https://stat.ethz.ch/mailman/listinfo/r-help>
> Emeritus Professor of Applied Statistics, University of Oxford
> 1 South Parks Road, Oxford OX1 3TG, UK




More information about the R-help mailing list