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]]

