[R-sig-Geo] Date indexing error for STFDF objects?

Edzer Pebesma edzer.pebesma at uni-muenster.de
Thu Jul 3 15:54:44 CEST 2014


Dear David, thanks for the clear report!

I believe this is a time zone issue -- in my time zone,

> date.ix
[1] "2009-03-21"
> class(date.ix)
[1] "Date"
> as.POSIXct(date.ix)
[1] "2009-03-21 01:00:00 CET"

internally xts, and hence spacetime, work with POSIXct time stamps.

If I run R with environmental variable TZ="", or TZ="GMT", I see

> as.POSIXct("2009-03-21")
[1] "2009-03-21 GMT"
> summary(rr[,"2009-03-21"]$PM10)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's
  13.71   20.06   26.45   31.94   31.03  269.10      32
> summary(rr[,"2009-03-22"]$PM10)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's
  3.523  10.150  14.410  15.970  21.830  31.080      32

would that be right?

# with TZ="" or TZ="GMT":
> range(index(rr))
[1] "2009-01-01" "2009-12-30"
# with TZ not set:
> range(index(rr))
[1] "2008-12-31" "2009-12-30"

So, it looks like the data set rr uses start-of-day time indexes, in
seconds (POSIXct), in GMT.

On 07/03/2014 02:16 PM, d.g.rossiter at utwente.nl wrote:
> Please see this as-simple-as-possible-but-no-simpler test; it appears to me as if date indexing is off by one day when extracting from STFDF objects.
> 
> ## packages and version
> require(sp); require(xts); require(spacetime); require(gstat)
> sessionInfo()
> ## R version 3.1.0 (2014-04-10)
> ## Platform: x86_64-w64-mingw32/x64 (64-bit)
> 
> ## locale ...
> 
> ## attached base packages:
> ## [1] stats     graphics  grDevices utils     datasets  methods
> ## [7] base
> 
> ## other attached packages:
> ## [1] gstat_1.0-19    spacetime_1.1-0 xts_0.9-7       zoo_1.7-11
> ## [5] sp_1.0-15
> 
> ## loaded via a namespace (and not attached):
> ## [1] FNN_1.1          grid_3.1.0       intervals_0.14.0
> ## [4] lattice_0.20-29  rgeos_0.3-5      tools_3.1.0
> 
> ## Germany & neighbours air quality test dataset
> data(air)
> rr <- rural[, "2009"] ## one year
> (ix <- which.max(rr$PM10)) ## which record has max PM10?
> station.xts <- rr[ix%%dim(rr)[1],] ## extract that station's time series
> summary(station.xts)
> ## date of maximum PM10 in this station's time series
> (date.xts <- station.xts[which.max(station.xts)])
> ## find index of the record with the maximum PM10
> (date.ix <- index(date.xts))
> as.numeric(date.ix)
> ## correctly extracts the record from the xts
> station.xts[date.ix]
> station.xts["2009-03-21"]
> as.numeric(date.ix)
> 
> ## now try to use this date index to
> ## extract all stations on that date
> ## from the STFDF object
> rr.maxpm <- rr[,date.ix]
> summary(rr.maxpm$PM10) ## wrong !!
> (date.ix.plus1 <- date.ix + 1) ## go to next day
> summary(rr[,date.ix.plus1]$PM10) ## right !!
> summary(rr[,"2009-03-21"]$PM10) ## wrong !!
> summary(rr[,"2009-03-22"]$PM10) ## right !!
> 
> ## conclusion -- indexing off by one day??
> -----------------------------------------------------------------------------------------------
> D G (David) Rossiter
> Department of Earth Systems Analysis
> University of Twente (NL)
> http://www.itc.nl/personal/rossiter
> 
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Heisenbergstraße 2, 48149 Münster, Germany. Phone: +49 251
83 33081 http://ifgi.uni-muenster.de GPG key ID 0xAC227795

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20140703/1a5cdfe0/attachment.bin>


More information about the R-sig-Geo mailing list