[R] Mistakes in date conversion for future date/time (POSIXct)

David Winsemius dwinsemius at comcast.net
Fri Apr 4 23:19:09 CEST 2014


On Apr 4, 2014, at 9:54 AM, Duncan Murdoch wrote:

> On 04/04/2014 10:55 AM, Winkler, Matthias wrote:
>> Dear R-users,
>> 
>> I'm working on datasets which contain data from the years 1960 to 2100 with a timestep of one hour. Every year has 365 days, leap years are ignored.
>> After reading the dataset with R I convert the column which contains date/time to POSIXct:
>> 
>> as.POSIXct(strptime(MyData [,1], format="%d.%m.%Y : %H"))
>> 
>> After that, I divide the data with split() into parts of one year each. Then I recognized, that the years for some rows are obviously converted wrong: They show years larger than 2100 (see example below).
>> I've controlled my original dataset, but the dates are correct there.
>> 
>> I also produced a date/time-sequence in R, which showed the same mistakes (see example below). The mistakes occur at the same dates like in my datasets. It's always at the end of march.
>> 
>> > datetimesequenz <- seq.POSIXt(from=as.POSIXct("1960-01-01 00:00"), to=as.POSIXct("2100-01-01 00:00"), by="1 hour")
>> > levels(as.factor(strftime(datetimesequenz, format="%Y")))
>>   [1] "1960" "1961" "1962" "1963" "1964" "1965" "1966" "1967" "1968" "1969" "1970" "1971" "1972" "1973" "1974" "1975" "1976" "1977"
>> [19] "1978" "1979" "1980" "1981" "1982" "1983" "1984" "1985" "1986" "1987" "1988" "1989" "1990" "1991" "1992" "1993" "1994" "1995"
>> [37] "1996" "1997" "1998" "1999" "2000" "2001" "2002" "2003" "2004" "2005" "2006" "2007" "2008" "2009" "2010" "2011" "2012" "2013"
>> [55] "2014" "2015" "2016" "2017" "2018" "2019" "2020" "2021" "2022" "2023" "2024" "2025" "2026" "2027" "2028" "2029" "2030" "2031"
>> [73] "2032" "2033" "2034" "2035" "2036" "2037" "2038" "2039" "2040" "2041" "2042" "2043" "2044" "2045" "2046" "2047" "2048" "2049"
>> [91] "2050" "2051" "2052" "2053" "2054" "2055" "2056" "2057" "2058" "2059" "2060" "2061" "2062" "2063" "2064" "2065" "2066" "2067"
>> [109] "2068" "2069" "2070" "2071" "2072" "2073" "2074" "2075" "2076" "2077" "2078" "2079" "2080" "2081" "2082" "2083" "2084" "2085"
>> [127] "2086" "2087" "2088" "2089" "2090" "2091" "2092" "2093" "2094" "2095" "2096" "2097" "2098" "2099" "2100" "2101" "2102" "2103"
>> [145] "2105" "2107" "2109" "2110" "2111" "2112" "2113" "2114" "2115" "2117" "2118" "2120" "2121" "2122" "2124" "2125" "2126" "2128"
>> [163] "2129" "2130" "2131" "2132" "2133" "2135" "2137" "2138" "2139" "2140" "2141" "2142" "2143" "2145" "2146" "2148" "2149" "2150"
>> [181] "2152" "2153" "2154" "2156" "2157" "2158" "2159" "2160" "2161" "2166"
>> 
>> Has anybody experienced the same problem and knows a workaround?
>> 
>> I'm using R 3.0.1 under Windows 7 64bit. I also tried this with R 3.0.3, it showed the same problem.
>> Thank you for your help!
> 
> I don't see this in 3.1.0 beta.  Do you?

I'm not seeing it on a Mac in 3.0.2 either.

> max(datetimesequenz)
[1] "2100-01-01 PST"
> length(datetimesequenz)
[1] 1227241

> 
> Duncan Murdoch

David Winsemius
Alameda, CA, USA




More information about the R-help mailing list