[R] time zone issue - beginners question
Gabor Grothendieck
ggrothendieck at gmail.com
Wed Jul 6 18:02:46 CEST 2011
On Wed, Jul 6, 2011 at 10:37 AM, B Laura <gm.spam2011 at gmail.com> wrote:
> Hello all!
>
> As beginner I'm struggling for a while with time zones issue and can't find
> a suitable solution.
> I would be grateful for any help.
>
> Dataset imported from excel has a variable transplant.date which has been
> recorded with CET time zone.
>
>> subDataset$transplant.date
> [1] "2000-01-01 CET" "2000-01-01 CET" "2000-01-02 CET" "2000-01-02 CET"
> "2000-01-02 CET" "2000-01-02 CET" "2000-01-04 CET" "2000-01-04 CET"
> "2000-01-04 CET" "2000-01-04 CET" "2000-01-04 CET" "2000-01-05 CET"
> "2000-01-05 CET"
> [14] "2000-01-05 CET" "2000-01-05 CET"
>
>
> However
>> Sys.time()
> [1] "2011-07-06 15:22:44 CEST"
>
> I need to calculate time difference in days but I'm still getting wrong
> calculations. Most likely is this time zone issue.
>
>
>> as.numeric(as.Date("2000-1-1")-as.Date(subDataset$transplant.date))
> [1] 1 1 0 0 0 0 -2 -2 -2 -2 -2 -3 -3 -3 -3
>
>
> Truncation doesn't help either
>
>>
> trunc(as.Date("2000-1-1"),"days")-trunc(as.Date(subDataset$transplant.date),"days")
> Time differences in days
> [1] 1 1 0 0 0 0 -2 -2 -2 -2 -2 -3 -3 -3 -3
>
>
If you don't have times, which seems to be the situation here, use
"Date" class rather than "POSIXct". Then you can't have time zone
issues in the first place. See R News 4/1.
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list