[R] how to get a histogram of an POSIXct vector ?

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Aug 23 13:39:05 CEST 2006


On Wed, 23 Aug 2006, Peter.Marx at knorr-bremse.com wrote:

> Hi,
> 
> search on web indicates that R also includes a hist method on POSIXct
> vectors.

> methods(hist)
[1] hist.Date*   hist.default hist.POSIXt*

   Non-visible functions are asterisked

so almost (objects of class POSIXct inherit from class POSIXt).

> My (perhaps too unexperienced) approach below yields an error.
> 
> Could somebody give me a hint what's wrong ?

samples is a data frame, not an object of class "POSIXct".
Try hist(samples$DateTime).

(And thanks for giving enough detail to enable us to spot the problem.)

> 
> Peter 
> 
> 
> > str(samples)
> `data.frame':   7500 obs. of  1 variable:
>  $ DateTime:'POSIXct', format: chr  "2006-07-20 00:10:08" "2006-07-20
> 00:11:17" "2006-07-20 00:11:23" 
> 
> >hist(samples)
> Error in hist.default(samples) : 'x' must be numeric
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list