[R] histogramming dates

Prof Brian D Ripley ripley at stats.ox.ac.uk
Wed May 29 08:43:55 CEST 2002


On Tue, 28 May 2002, Don MacQueen wrote:

> One way would be to convert to POSIXlt and extract the month element.
> Then you should be able to tabulate the number of events in each
> month, and make a barplot of those.
> -Don

This is done for you automatically by the seq method for dates.
However, the issue here is I think that `breaks' needs to be numeric,
so you need to unclass the value given.

>
> At 4:57 PM -0500 5/28/02, Michael A. Miller wrote:
> >I'd like to make a plot showing frequency of an event.  The data
> >is in a data from that includes Year, Month and Day (of month)
> >fields, so I created a Date with ISOdate(Year, Month, Day,
> >tz='').  I can plot frequencies for the year 2002 with
> >
> >   > thisyear <- Date[Year==2002]
> >   > hist( thisyear, xaxt='n' )
> >   > axis.POSIXct( 1, at=seq(min(thisyear), max(thisyear), by="month"),
> >                  format='%b %Y' )
> >
> >Now I want to specify the histogram breaks so that there is one
> >bin per month, so I tried this:
> >
> >   > hist( thisyear,
> >        breaks=ISOdate( rep(2002,12), seq(12), rep(1,12), tz='' ),
> >        xaxt='n' )
> >
> >That resulted in an error message that said:
> >
> >   Error in Ops.POSIXt(1e-07, mean(h)) : * not defined for POSIXt objects
> >
> >Can anyone suggest a way to do this?  Or another method for
> >plotting this sort of month by month frequency plot?  For a
> >single year I could histogram the month, but I'd like to be able
> >to span any date range, including multiple years.
> >
> >Mike
> >
> >--
> >Michael A. Miller                               mmiller3 at iupui.edu
> >   Imaging Sciences, Department of Radiology, IU School of Medicine
> >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> >r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> >Send "info", "help", or "[un]subscribe"
> >(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> >_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list