[R] cut.POSIXct problem

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jun 17 11:41:49 CEST 2003


This works in R 1.7.1: please upgrade.

[That's assuming that your sequence actually covers the data: you need to
go beyond max(cas.param) to be sure, and it looks to me that with 
right=FALSE and include.lowest-FALSE the breaks never will cover the 
data.]


On Tue, 17 Jun 2003, Petr Pikal wrote:

> Dear all
> 
> I would like to aggregate a data frame in a three minute interval. I have a time 
> vector:
> 
> > str(cas.param)
> `POSIXct', format: chr [1:181] "2003-06-12 09:00:00" "2003-06-12 09:01:00" 
> "2003-06-12 09:02:00" 
> 
> and I want to turn it into a factor by cut. It works if I want to break it in let say 
> hours
> 
> > str(cut(cas.param,breaks="hour"))
>  Factor w/ 3 levels "2003-06-12 ..",..: 1 1 1 1 1 1 1 1 1 1 .
> 
> But if i tried to do similar task but to construct three minutes intervals with a 
> vector of cut points it gives me an error
> 
> > cut(cas.param,breaks=seq(min(cas.param),max(cas.param), by="3 mins"))
> Error in sort(breaks) : `x' must be atomic
> 
> however
> 
> > str(seq(min(cas.param),max(cas.param), by="3 mins"))
> `POSIXct', format: chr [1:61] "2003-06-12 09:00:00" "2003-06-12 09:03:00" 
> "2003-06-12 09:06:00"
> 
> works.
> 
> So it is definitely my lack of understanding how to implement a vector of cut 
> points (constructed by seq()), to break parameter of cut() function.
> 
> Please can you give me any hints?
> 
> R 1.7.0, Windows NT
> 
> Thanks a lot
> 
> Petr Pikal
> petr.pikal at precheza.cz
> p.pik at volny.cz
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 

-- 
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