### R code from vignette source 'sto.Rnw'

###################################################
### code chunk number 1: sto.Rnw:88-89 (eval = FALSE)
###################################################
## over(x, geometry(y))


###################################################
### code chunk number 2: sto.Rnw:96-97 (eval = FALSE)
###################################################
## over(x, y)


###################################################
### code chunk number 3: sto.Rnw:105-106 (eval = FALSE)
###################################################
## over(x, y, returnList = TRUE)


###################################################
### code chunk number 4: sto.Rnw:117-120
###################################################
library(sp)
library(spacetime)
showMethods(over)


###################################################
### code chunk number 5: sto.Rnw:132-133 (eval = FALSE)
###################################################
## over(x, y)


###################################################
### code chunk number 6: sto.Rnw:181-182 (eval = FALSE)
###################################################
## aggregate(x, by, FUN, ..., simplify = TRUE)


###################################################
### code chunk number 7: sto.Rnw:198-202
###################################################
data(air)
rural = STFDF(stations, dates, data.frame(PM10 = as.vector(air)))
class(rural)
class(DE_NUTS1)


###################################################
### code chunk number 8: sto.Rnw:214-216
###################################################
x = as(rural[,"2008"], "xts")
apply(x, 1, mean, na.rm=TRUE)[1:5]


###################################################
### code chunk number 9: sto.Rnw:222-227
###################################################
dim(rural[,"2008"])
x = aggregate(rural[,"2008"], DE_NUTS1, mean, na.rm=TRUE)
dim(x)
summary(x)
stplot(x, mode = "tp")


###################################################
### code chunk number 10: sto.Rnw:231-232 (eval = FALSE)
###################################################
## stplot(x, mode = "tp", par.strip.text = list(cex=.5))


###################################################
### code chunk number 11: sto.Rnw:236-237
###################################################
print(stplot(x, mode = "tp", par.strip.text = list(cex=.5)))


###################################################
### code chunk number 12: sto.Rnw:247-250
###################################################
x = aggregate(rural[,"2008"], DE, mean, na.rm=TRUE)
class(x)
plot(x[,"PM10"])


###################################################
### code chunk number 13: sto.Rnw:255-256
###################################################
plot(x[,"PM10"])


###################################################
### code chunk number 14: sto.Rnw:267-269
###################################################
x = as(rural[,"2008"], "xts")
apply(x, 2, mean, na.rm=TRUE)[1:5]


###################################################
### code chunk number 15: sto.Rnw:276-279
###################################################
sel = which(!apply(as(rural[,"2008"], "xts"), 2, function(x) all(is.na(x))))
x = aggregate(rural[sel,"2008"], "month", mean, na.rm=TRUE)
stplot(x, mode = "tp")


###################################################
### code chunk number 16: sto.Rnw:284-285
###################################################
print(stplot(x, mode = "tp", par.strip.text = list(cex=.5)))


###################################################
### code chunk number 17: sto.Rnw:301-304
###################################################
library(zoo)
x = aggregate(rural[sel,"2005::2011"], as.yearqtr, median, na.rm=TRUE)
stplot(x, mode = "tp")


###################################################
### code chunk number 18: sto.Rnw:309-310
###################################################
as.year <- function(x) as.numeric(floor(as.yearmon(x)))


###################################################
### code chunk number 19: sto.Rnw:316-317
###################################################
print(stplot(x, mode = "tp", par.strip.text = list(cex=.5)))


###################################################
### code chunk number 20: sto.Rnw:327-329
###################################################
DE.years = STF(DE, as.Date(c("2008-01-01", "2009-01-01")))
aggregate(rural[,"2008::2009"], DE.years, mean, na.rm=TRUE)
