Skip to content

histogram of dates

2 messages · Terry Therneau, Marc Schwartz

#
I can't seem to get a histogram of dates:

tmt910% R --vanilla

R version 2.13.0 (2011-04-13)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
...
[1] "1970-01-02" "1970-07-20"
Error in .Internal(inherits(x, what, which)) : 'x' is missing
3: inherits(breaks, "Date")
2: hist.Date(temp)
1: hist(temp)

Existence of hist.Date implies that this is intended to work.
The MASS version fails in a different way.
Error in Ops.difftime(n, 2) : '%/%' not defined for "difftime" objects
R version 2.13.0 (2011-04-13)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=C              
 [5] LC_MONETARY=C              LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods
base     

other attached packages:
[1] MASS_7.3-12

Terry Therneau
#
On Apr 22, 2011, at 12:31 PM, Terry Therneau wrote:

            
Hi Terry,

Try this:

  temp <- as.Date(1:200, origin="1970/01/01")

  hist(temp, breaks = "months")


There is no default for the 'breaks' argument in hist.Date() and there does not appear to be a check for a missing value for this argument.

truehist() does not have a method for Date class objects, but you could do:

  truehist(as.numeric(temp))

or perhaps use cut.Date() on the vector and create the intervals/breakpoints that you wish to use.

HTH,

Marc Schwartz