javier garcia - CEBAS
2004-Aug-17 10:48 UTC
[R] strptime() bug? And additional problem in package "tseries"
Hi all, I've got some problems with irts objects, one of which could be a bug: 1) Read a table with several columns from Postgres and the first column is Timestamp with timezone (this is OK). An extract is: raincida$ts: [2039] "25/03/2000 22:00:00 UTC" "25/03/2000 23:00:00 UTC" [2041] "26/03/2000 00:00:00 UTC" "26/03/2000 01:00:00 UTC" [2043] "26/03/2000 02:00:00 UTC" "26/03/2000 03:00:00 UTC" [2045] "26/03/2000 04:00:00 UTC" "26/03/2000 05:00:00 UTC" 2) Try to extract time from this column of the dataframe (bug?)> lluvia.strptime <- strptime(raincida$ts, format="%d/%m/%Y %H:%M:%S")# An extract is: [2038] "2000-03-25 21:00:00" "2000-03-25 22:00:00" "2000-03-25 23:00:00" [2041] "2000-03-26 00:00:00" "2000-03-26 01:00:00" "2000-03-26 03:00:00" [2044] "2000-03-26 03:00:00" "2000-03-26 04:00:00" "2000-03-26 05:00:00" # note that element [2043] is wrong. This happens several times in # the dataset. This will produce an eventual error because of omitted # and duplicated values 3) The additional problem is related with function time() for irts objects. I try to make an irts from several columns of the table read:> rain.irts <-irts(as.POSIXct(lluvia.strptime,tz="GMT"),cbind(raincida[[8]],raincida[[9]],raincida[[10]],raincida[[11]],raincida[[12]],raincida[[13]],raincida[[14]])) # this step doesn't seem to have any further problem. An extract is: 2000-03-25 22:00:00 GMT 0.275 0 0.07875 0.2 0 0.025 23.65 2000-03-25 23:00:00 GMT 0.275 0 0.07875 0.2 0 0.025 23.65 2000-03-26 00:00:00 GMT 0 0 0.001667 0.008333 0 0 0.5322 2000-03-26 01:00:00 GMT 0 0 0.001667 0.008333 0 0 0.5322 2000-03-26 03:00:00 GMT 0 0 0.001667 0.008333 0 0 0.5322 2000-03-26 03:00:00 GMT 0 0 0.001667 0.008333 0 0 0.5322 2000-03-26 04:00:00 GMT 0 0 0.001667 0.008333 0 0 0.5322 # But I try to extract the time part:>time(rain.irts, tz='GMT')# An extract is: [2039] "2000-03-25 23:00:00 CET" "2000-03-26 00:00:00 CET" [2041] "2000-03-26 01:00:00 CET" "2000-03-26 03:00:00 CEST" [2043] "2000-03-26 05:00:00 CEST" "2000-03-26 05:00:00 CEST" # There isn't a way for this time to be shown as 'GMT'? I guess sometimes it is shown as 'CET' and other times as 'CEST' depending of the lag between the locale and gmt (utc) times. But for me this is an additional problem as the output shows one or two hours more that UTC time. Thanks all, and best regards, Javier G.
Prof Brian Ripley
2004-Aug-17 11:04 UTC
NO bug in Re: [R] strptime() bug? And additional problem in package "tseries"
There is no bug in R here. There was a change to DST in Spain at 2am on 2000-03-26, and they are *printed* as times in your locale, as documented. Please read the posting guide and FAQ about what is a bug. Also, please try not to confuse an object and its printed representation. On Tue, 17 Aug 2004, javier garcia - CEBAS wrote:> Hi all, I've got some problems with irts objects, one of which could be a bug: > > 1) Read a table with several columns from Postgres and the first column is > Timestamp with timezone (this is OK). An extract is: > > raincida$ts: > [2039] "25/03/2000 22:00:00 UTC" "25/03/2000 23:00:00 UTC" > [2041] "26/03/2000 00:00:00 UTC" "26/03/2000 01:00:00 UTC" > [2043] "26/03/2000 02:00:00 UTC" "26/03/2000 03:00:00 UTC" > [2045] "26/03/2000 04:00:00 UTC" "26/03/2000 05:00:00 UTC" > > 2) Try to extract time from this column of the dataframe (bug?) > > > lluvia.strptime <- strptime(raincida$ts, format="%d/%m/%Y %H:%M:%S") > > # An extract is:NO! That is an extract of *printing* lluvia.strptime, which will give you the times in your current time zone, as documented.> [2038] "2000-03-25 21:00:00" "2000-03-25 22:00:00" "2000-03-25 23:00:00" > [2041] "2000-03-26 00:00:00" "2000-03-26 01:00:00" "2000-03-26 03:00:00" > [2044] "2000-03-26 03:00:00" "2000-03-26 04:00:00" "2000-03-26 05:00:00" > > # note that element [2043] is wrong. This happens several times in > # the dataset. This will produce an eventual error because of omitted > # and duplicated valuesI think you want to use as.POSIXct(lluvia.strptime, tz="GMT") to get what you may have intended. .... -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595