[R-sig-Geo] spacetime: creating STIDF objects

Roland Harhoff rolandh at uni-muenster.de
Thu Nov 9 15:15:12 CET 2017


Hey Facundo,

I'm not sure about the stConstruct issue (yet) ...
but you can create a STIDF object from your example data by

mystidf <- STIDF(rbind(sp,sp,sp,sp), mydata$time, mydata[ , "values", drop = F])

See also the documentation ...

?spacetime::STIDF

HTH!

Best wishes ...

Roland


Facundo Muñoz schrieb am 2017-11-09:
> Dear all, I have just posted an issue [1] in the GitHub repository for
> the "spacetime" package that I reproduce here:

> I have a "long" table with irregular data (observations for some
> municipalities at specific months) that I would like to store together
> with the administrative map of the region (SpatialPolygons). I tried
> unsuccessfully to directly create the STIDF object using both
> `stConstruct()` and `STIDF`.

> In all the related examples in the package you first create a STFDF
> which is later coerced to STIDF. But my dataset is very sparse.

> Here is a reproducible example adapted from the examples in the package.
> If I use the complete table it leads to a STFDF object as expected and
> it works fine. However if the table is not complete it should switch to
> a STIDF representation (as far as I understand from the JSS paper).

> ``` r

> library(spacetime)
> library(sp)
> sp = cbind(x = c(0,0,1), y = c(0,1,1))
> row.names(sp) = paste0("point", 1:nrow(sp))
> sp = SpatialPoints(sp)
> time = as.POSIXct("2010-08-05")+3600*(10:13)
> m = c(10,20,30) # means for each of the 3 point locations
> mydata = rnorm(length(sp)*length(time),mean=rep(m, 4))

> mydata = data.frame(
>   space = rep(row.names(sp), 4),
>   time  = rep(time, each = 3),
>   values = signif(mydata,3)
> )

> mystfdf <- stConstruct(mydata, "space", "time", sp)  # This works OK

> mystidf <- stConstruct(mydata[-1,], "space", "time", sp)
> #> Error: nrow(object at time) == length(object at sp) is not TRUE
> ```


> Thank you in advance.

> ƒacu.-


> [1] https://github.com/edzer/spacetime/issues/30

> --
> Cirad <https://umr-astre.cirad.fr/>
> *Facundo Muñoz*
> /Biostatistician/
> Bios - UMR ASTRE
> Bureau E-203 - TA A-117 / E
> Campus international de Baillarguet
> 34398 Montpellier Cedex 5
> France
> +33 467 593 868
> @famuvie

> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list