[R] hours() in 'chron': output != input

Gabor Grothendieck ggrothendieck at gmail.com
Wed Sep 20 21:06:11 CEST 2006


I think hours should have a comparison tolerance.  Try:

   hours(x+1e-10)

as a workaround.

On 9/20/06, Glen A Sargeant <glen_sargeant at usgs.gov> wrote:
> I encountered surprising (to me, at least) behavior while using 'hours()'
> in package 'chron.' I will be grateful if someone can point out my error
> or provide an explanation and intuitive solution (I suppose I could
> convert chron to a character vector and use substring, but I deal mostly
> with newbies and kludgy approaches don't inspire much confidence).
>
> I used 2.3.0 to construct the dataframe below.
>
> 1) 'date.char' is a character vector
>
> 2) 'time.char' is a character vector
>
> 3) 'chron' was created by
> >chron(dates(date.char),times(time.char))
>
> 4) hours were extracted with
> >hours(chron).
>
> 5) Note that the hours used to construct 'chron' do not match the hours
> extracted with 'hours()' when minutes and seconds are "00:00."
>
>   date.char time.char               chron hour
> 1   09/20/06  00:00:00 (09/20/06 00:00:00)    0
> 2   09/20/06  01:00:00 (09/20/06 01:00:00)    0
> 3   09/20/06  02:00:00 (09/20/06 02:00:00)    2
> 4   09/20/06  03:00:00 (09/20/06 03:00:00)    3
> 5   09/20/06  04:00:00 (09/20/06 04:00:00)    3
> 6   09/20/06  05:00:00 (09/20/06 05:00:00)    5
> 7   09/20/06  06:00:00 (09/20/06 06:00:00)    6
> 8   09/20/06  07:00:00 (09/20/06 07:00:00)    6
> 9   09/20/06  08:00:00 (09/20/06 08:00:00)    8
> 10  09/20/06  09:00:00 (09/20/06 09:00:00)    9
> 11  09/20/06  10:00:00 (09/20/06 10:00:00)    9
> 12  09/20/06  11:00:00 (09/20/06 11:00:00)   11
> 13  09/20/06  12:00:00 (09/20/06 12:00:00)   12
> 14  09/20/06  13:00:00 (09/20/06 13:00:00)   12
> 15  09/20/06  14:00:00 (09/20/06 14:00:00)   14
> 16  09/20/06  15:00:00 (09/20/06 15:00:00)   15
> 17  09/20/06  16:00:00 (09/20/06 16:00:00)   15
> 18  09/20/06  17:00:00 (09/20/06 17:00:00)   17
> 19  09/20/06  18:00:00 (09/20/06 18:00:00)   18
> 20  09/20/06  19:00:00 (09/20/06 19:00:00)   18
> 21  09/20/06  20:00:00 (09/20/06 20:00:00)   20
> 22  09/20/06  21:00:00 (09/20/06 21:00:00)   21
> 23  09/20/06  22:00:00 (09/20/06 22:00:00)   21
> 24  09/20/06  23:00:00 (09/20/06 23:00:00)   23
>
> This behavior is problematic if one wants to extract hours and use them to
> group data.
>
> Regards,
>
> Glen Sargeant
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list