Skip to content

STFDF with n variables

6 messages · piero campa, Piero Campalani, Edzer Pebesma

#
Dear list,
I am going to build a spacetime::STFDF object where the "n" spatial
locations hold "h" different values (different fields) over the "m" times.

Along the documentation (spacetime vignette, ?stConstruct, ?STFDF, ?reshape)
I only found examples with layout of {n?m?1} observations, and not {n?m?h}
as in my case.
[I might as well have missed such examples, so please forgive me in that
case]

I am writing here to have a confirmation that I am doing things correctly.
This is a toy-example of my workflow (letting out CRS or ending-times
details):

-----------------------------------
library(gstat)
library(spacetime)
data(meuse)
# subset
meuse <- meuse[c("cadmium", "copper", "x", "y")][1:10,]
coordinates(meuse) <- ~x+y
#
ds <- slot(meuse, "data")
meuse <- as(meuse, "SpatialPoints")
# append hypothetical values to match cardinality of data required
ds <- rbind(ds, ds+1)
# Assign dates
dts <- as.Date(c(1:2))
ds <- cbind(ds, time=sort(rep(dts,10)), id=1:nrow(ds))
# Rename field variables to avoid conflict
#names(ds) <- c("cadmiums", "coppers", "time", "id")
# Build the spacetime object: n=10, m=2, h=2
stMeuse = STFDF(meuse, dts, ds) 
str(stMeuse)
-----------------------------------

Thanks for any comment.
Piero







--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/STFDF-with-n-variables-tp7581966.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
#
On 12/16/2012 06:32 PM, piero campa wrote:
Yes, that works:
[1] "STFDF"
attr(,"package")
[1] "spacetime"
space      time variables
       10         2         4


stConstruct would need extension to be help here, it tries to build
STFDF objects from time- or space-wide tables -- with multiple
attributes, the organization of such tables is not unambiguous.

(also note that with the CRAN version of spacetime, you'd need to load
package zoo first in order to run your script)

  
    
#
Piero,

in your case id is simply an attribute, so it can have any value, as you
can see from:

stplot(stMeuse[,,1:4], mode = 'ts')

what is the special purpose of your IDs, what should they identify?
On 12/16/2012 07:42 PM, Piero Campalani wrote:

  
    
#
On 12/16/2012 08:28 PM, Piero Campalani wrote:
Piero, there is a chance: if the layout is complete (full: STFDF) you
can recreate space and time ID from row order,
[1]  1  2  3  4  5  6  7  8  9 10  1  2  3  4  5  6  7  8  9 10
[1] 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2

For an irregular layout, STIDF, the IDs are kept in the index slot.

Indeed, you need to know that space cycles fastest, and so it is easy to
make mistakes.