[R] as.Date question
Felix Andrews
felix at nfrac.org
Mon Dec 21 13:49:19 CET 2009
I don't know the details of why this is happening, but in any case it
is a good idea to round() your times if you want to convert them to
dates. Just as you would round() a numeric value to convert it to an
integer.
as.Date(round(zzz1, "days"))
2009/12/21 Jason Morgan <jwm-r-help at skepsi.net>:
> Hello,
>
> On 2009.12.20 18:06:17, MAL wrote:
>> All!
>>
>> This piece of code:
>>
>> zzz1 <- as.POSIXct("1999-03-18", tz="CET")
>> zzz2 <- as.POSIXlt("1999-03-18", tz="CET")
>> zzz1 == zzz2
>> as.Date(zzz1)
>> as.Date(zzz2)
>>
>> yields TRUE for "zzz1==zzz2", but the two dates returned by as.Date are different:
>>
>> > as.Date(zzz1)
>> [1] "1999-03-17"
>> > as.Date(zzz2)
>> [1] "1999-03-18"
>>
>> I'm using R 2.10.0.
>>
>> Would be glad for any clarifications. Thanks!
>
> I don't know why as.Date() is giving different results, but if look at
> the value of the variables, they are equal:
>
>> zzz1 <- as.POSIXct("1999-03-18", tz="CET")
>> zzz2 <- as.POSIXlt("1999-03-18", tz="CET")
>> zzz1 == zzz2
> [1] TRUE
>> as.Date(zzz1)
> [1] "1999-03-17"
>> as.Date(zzz2)
> [1] "1999-03-18"
>> zzz1
> [1] "1999-03-18 CET"
>> zzz2
> [1] "1999-03-18 CET"
>
> Maybe someone here can explain the behavior of as.Date().
>
> Cheers,
> ~Jason
>
>
> --
> Jason W. Morgan
> Graduate Student
> Department of Political Science
> *The Ohio State University*
> 154 North Oval Mall
> Columbus, Ohio 43210
>
> ______________________________________________
> R-help at r-project.org 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.
>
--
Felix Andrews / 安福立
Postdoctoral Fellow
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 4670
E: felix.andrews at anu.edu.au
CRICOS Provider No. 00120C
--
http://www.neurofractal.org/felix/
More information about the R-help
mailing list