[R] cut.Date functionality for chron date/time objects

Gabor Grothendieck ggrothendieck at gmail.com
Wed Aug 3 01:21:48 CEST 2005


Assuming, as in your post:

set.seed(123)
mychron <- chron(sort(runif(10, 0, 10)))
breaks <- quantile(mychron)

# is one of these adequate?

cut(mychron, breaks)

cut(unclass(mychron), unclass(breaks), lab = FALSE)



On 8/2/05, Sebastian Luque <spluque at gmail.com> wrote:
> Hello,
> 
> I've encountered the need to cut some chron objects of the form:
> 
> R> mychron <- chron(sort(runif(10, 0, 10)))
> R> mychron
>  [1] (01/01/70 16:36:20) (01/02/70 00:08:46) (01/03/70 16:54:49)
>  [4] (01/04/70 06:45:00) (01/07/70 06:21:24) (01/07/70 18:28:44)
>  [7] (01/08/70 00:47:05) (01/08/70 05:11:44) (01/10/70 01:07:53)
> [10] (01/10/70 17:46:53)
> 
> into arbitrary (e.g. a given number of minutes, seconds, etc.) units.
> Basically, I'm searching for the functionality of cut.Date, which has a
> nice 'breaks' argument:
> 
> 
> ,-----[ *help[R](cut.Date)* (lines: 23 - 30) ]
> |   breaks: a vector of cut points _or_ number giving the number of
> |           intervals which 'x' is to be cut into _or_ an interval
> |           specification, one of '"sec"', '"min"', '"hour"', '"day"',
> |           '"DSTday"', '"week"', '"month"' or '"year"', optionally
> |           preceded by an integer and a space, or followed by '"s"'.
> |           For '"Date"' objects only '"day"', '"week"', '"month"' and
> |           '"year"' are allowed.
> `-----
> 
> 'cut.dates' (from chron itself) allows for cut'ing into months, years,
> etc., but not any fractions or multiples of these.
> 
> Converting the chron objects to POSIXct (via 'as.POSIXct') and then using
> cut.Date works, but is inconvenient, as it introduces time zone
> information. Is there a better way to deal with this?
> 
> Thanks in advance,
> --
> Sebastian P. Luque
> 
> ______________________________________________
> 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
>




More information about the R-help mailing list