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

Spencer Graves spencer.graves at pdf.com
Wed Aug 3 03:45:15 CEST 2005


How about the following:

 > set.seed(123)
 > mychron <- chron(sort(runif(10, 0, 10)))
 > (breaks <- chron(pretty(quantile(mychron))))
[1] 01/01/70 01/03/70 01/05/70 01/07/70 01/09/70 01/11/70
 >
spencer graves

Sebastian Luque wrote:

> Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> 
>>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)
> 
> 
> Thank you Gabor, that showed me I really needed to be more creative with
> the 'breaks' argument. So what I needed was (with mychron as above):
> 
> breaks <- seq(min(mychron, na.rm = TRUE),
>               ceiling(max(mychron, na.rm = TRUE)), by = 1/2)
> 
> cut(unclass(mychron), unclass(breaks),
>     include.lowest = TRUE, labels = FALSE)
> 
> 
> in order to cut the chron object into 1/2 day units.
> 
> 
> Thanks so much,

-- 
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA

spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel:  408-938-4420
Fax: 408-280-7915




More information about the R-help mailing list