R Under development (unstable) (2024-09-03 r87093 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > options(digits=5) > options(xts_check_TZ=FALSE) > ################################################### > ### chunk number 4: > ################################################### > library(sp) > library(spacetime) > set.seed(13579) # to make outcome a bit predictable! > sp = cbind(x = c(0,0,1), y = c(0,1,1)) > row.names(sp) = paste("point", 1:nrow(sp), sep="") > sp = SpatialPoints(sp) > time = as.POSIXct("2010-08-05", tz="GMT")+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)) > IDs = paste("ID", 1:length(mydata), sep = "_") > mydata = data.frame(values = signif(mydata,3), ID=IDs) > stfdf = STFDF(sp, time, mydata) > > > ################################################### > ### chunk number 5: > ################################################### > format(as.data.frame(stfdf, row.names = IDs), tz="GMT") x y sp.ID time endTime timeIndex values ID ID_1 0 0 point1 2010-08-05 10:00:00 2010-08-05 11:00:00 1 8.77 ID_1 ID_2 0 1 point2 2010-08-05 10:00:00 2010-08-05 11:00:00 1 18.70 ID_2 ID_3 1 1 point3 2010-08-05 10:00:00 2010-08-05 11:00:00 1 29.70 ID_3 ID_4 0 0 point1 2010-08-05 11:00:00 2010-08-05 12:00:00 2 8.47 ID_4 ID_5 0 1 point2 2010-08-05 11:00:00 2010-08-05 12:00:00 2 21.10 ID_5 ID_6 1 1 point3 2010-08-05 11:00:00 2010-08-05 12:00:00 2 32.50 ID_6 ID_7 0 0 point1 2010-08-05 12:00:00 2010-08-05 13:00:00 3 10.80 ID_7 ID_8 0 1 point2 2010-08-05 12:00:00 2010-08-05 13:00:00 3 20.20 ID_8 ID_9 1 1 point3 2010-08-05 12:00:00 2010-08-05 13:00:00 3 29.00 ID_9 ID_10 0 0 point1 2010-08-05 13:00:00 2010-08-05 14:00:00 4 9.74 ID_10 ID_11 0 1 point2 2010-08-05 13:00:00 2010-08-05 14:00:00 4 20.70 ID_11 ID_12 1 1 point3 2010-08-05 13:00:00 2010-08-05 14:00:00 4 30.50 ID_12 > format(as(stfdf, "data.frame")[1:4,], tz="GMT") x y sp.ID time endTime timeIndex values ID 1 0 0 point1 2010-08-05 10:00:00 2010-08-05 11:00:00 1 8.77 ID_1 2 0 1 point2 2010-08-05 10:00:00 2010-08-05 11:00:00 1 18.70 ID_2 3 1 1 point3 2010-08-05 10:00:00 2010-08-05 11:00:00 1 29.70 ID_3 4 0 0 point1 2010-08-05 11:00:00 2010-08-05 12:00:00 2 8.47 ID_4 > > ################################################### > ### chunk number 6: > ################################################### > unstack(stfdf) point1 point2 point3 2010-08-05 10:00:00 8.77 18.7 29.7 2010-08-05 11:00:00 8.47 21.1 32.5 2010-08-05 12:00:00 10.80 20.2 29.0 2010-08-05 13:00:00 9.74 20.7 30.5 > t(unstack(stfdf)) 2010-08-05 10:00:00 2010-08-05 11:00:00 2010-08-05 12:00:00 point1 8.77 8.47 10.8 point2 18.70 21.10 20.2 point3 29.70 32.50 29.0 2010-08-05 13:00:00 point1 9.74 point2 20.70 point3 30.50 > unstack(stfdf, which = 2) point1 point2 point3 2010-08-05 10:00:00 ID_1 ID_2 ID_3 2010-08-05 11:00:00 ID_4 ID_5 ID_6 2010-08-05 12:00:00 ID_7 ID_8 ID_9 2010-08-05 13:00:00 ID_10 ID_11 ID_12 > > ################################################### > ### chunk number 7: > ################################################### > as(stfdf[,,1], "xts") point1 point2 point3 2010-08-05 10:00:00 8.77 18.7 29.7 2010-08-05 11:00:00 8.47 21.1 32.5 2010-08-05 12:00:00 10.80 20.2 29.0 2010-08-05 13:00:00 9.74 20.7 30.5 > as(stfdf[,,2], "xts") point1 point2 point3 2010-08-05 10:00:00 ID_1 ID_2 ID_3 2010-08-05 11:00:00 ID_4 ID_5 ID_6 2010-08-05 12:00:00 ID_7 ID_8 ID_9 2010-08-05 13:00:00 ID_10 ID_11 ID_12 > > ################################################### > ### chunk number 8: > ################################################### > stfdf[[1]] [1] 8.77 18.70 29.70 8.47 21.10 32.50 10.80 20.20 29.00 9.74 20.70 30.50 > stfdf[["values"]] [1] 8.77 18.70 29.70 8.47 21.10 32.50 10.80 20.20 29.00 9.74 20.70 30.50 > stfdf[["newVal"]] <- rnorm(12) > stfdf$ID [1] "ID_1" "ID_2" "ID_3" "ID_4" "ID_5" "ID_6" "ID_7" "ID_8" "ID_9" [10] "ID_10" "ID_11" "ID_12" > stfdf$ID = paste("OldIDs", 1:12, sep="") > stfdf$NewID = paste("NewIDs", 12:1, sep="") > stfdf An object of class "STFDF" Slot "data": values ID newVal NewID 1 8.77 OldIDs1 -0.766670 NewIDs12 2 18.70 OldIDs2 -0.437290 NewIDs11 3 29.70 OldIDs3 -0.471551 NewIDs10 4 8.47 OldIDs4 -0.561384 NewIDs9 5 21.10 OldIDs5 -1.215165 NewIDs8 6 32.50 OldIDs6 0.246818 NewIDs7 7 10.80 OldIDs7 -0.861698 NewIDs6 8 20.20 OldIDs8 0.659911 NewIDs5 9 29.00 OldIDs9 -0.036842 NewIDs4 10 9.74 OldIDs10 -0.952524 NewIDs3 11 20.70 OldIDs11 -1.699710 NewIDs2 12 30.50 OldIDs12 0.899851 NewIDs1 Slot "sp": SpatialPoints: x y point1 0 0 point2 0 1 point3 1 1 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 2010-08-05 11:00:00 2 2010-08-05 12:00:00 3 2010-08-05 13:00:00 4 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" "2010-08-05 12:00:00 GMT" [3] "2010-08-05 13:00:00 GMT" "2010-08-05 14:00:00 GMT" > > > ################################################### > ### chunk number 9: > ################################################### > stfdf[,1] # SpatialPointsDataFrame: coordinates values ID newVal NewID 1 (0, 0) 8.77 OldIDs1 -0.76667 NewIDs12 2 (0, 1) 18.70 OldIDs2 -0.43729 NewIDs11 3 (1, 1) 29.70 OldIDs3 -0.47155 NewIDs10 > stfdf[,,1] An object of class "STFDF" Slot "data": values 1 8.77 2 18.70 3 29.70 4 8.47 5 21.10 6 32.50 7 10.80 8 20.20 9 29.00 10 9.74 11 20.70 12 30.50 Slot "sp": SpatialPoints: x y point1 0 0 point2 0 1 point3 1 1 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 2010-08-05 11:00:00 2 2010-08-05 12:00:00 3 2010-08-05 13:00:00 4 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" "2010-08-05 12:00:00 GMT" [3] "2010-08-05 13:00:00 GMT" "2010-08-05 14:00:00 GMT" > stfdf[1,,1] # xts values timeIndex 2010-08-05 10:00:00 8.77 1 2010-08-05 11:00:00 8.47 2 2010-08-05 12:00:00 10.80 3 2010-08-05 13:00:00 9.74 4 > stfdf[,,"ID"] An object of class "STFDF" Slot "data": ID 1 OldIDs1 2 OldIDs2 3 OldIDs3 4 OldIDs4 5 OldIDs5 6 OldIDs6 7 OldIDs7 8 OldIDs8 9 OldIDs9 10 OldIDs10 11 OldIDs11 12 OldIDs12 Slot "sp": SpatialPoints: x y point1 0 0 point2 0 1 point3 1 1 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 2010-08-05 11:00:00 2 2010-08-05 12:00:00 3 2010-08-05 13:00:00 4 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" "2010-08-05 12:00:00 GMT" [3] "2010-08-05 13:00:00 GMT" "2010-08-05 14:00:00 GMT" > stfdf[1,,"values", drop=FALSE] # stays STFDF: An object of class "STFDF" Slot "data": values 1 8.77 2 8.47 3 10.80 4 9.74 Slot "sp": SpatialPoints: x y point1 0 0 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 2010-08-05 11:00:00 2 2010-08-05 12:00:00 3 2010-08-05 13:00:00 4 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" "2010-08-05 12:00:00 GMT" [3] "2010-08-05 13:00:00 GMT" "2010-08-05 14:00:00 GMT" > stfdf[,1, drop=FALSE] #stays STFDF An object of class "STFDF" Slot "data": values ID newVal NewID 1 8.77 OldIDs1 -0.76667 NewIDs12 2 18.70 OldIDs2 -0.43729 NewIDs11 3 29.70 OldIDs3 -0.47155 NewIDs10 Slot "sp": SpatialPoints: x y point1 0 0 point2 0 1 point3 1 1 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" > > ################################################### > ### chunk number 10: > ################################################### > showClass("STSDF") Class "STSDF" [package "spacetime"] Slots: Name: data index sp time endTime Class: data.frame matrix Spatial xts POSIXct Extends: Class "STS", directly Class "ST", by class "STS", distance 2 > > ################################################### > ### chunk number 11: > ################################################### > showClass("STIDF") Class "STIDF" [package "spacetime"] Slots: Name: data sp time endTime Class: data.frame Spatial xts POSIXct Extends: Class "STI", directly Class "ST", by class "STI", distance 2 > sp = expand.grid(x = 1:3, y = 1:3) > row.names(sp) = paste("point", 1:nrow(sp), sep="") > sp = SpatialPoints(sp) > time = as.POSIXct("2010-08-05", tz="GMT")+3600*(11:19) > m = 1:9 * 10 # means for each of the 9 point locations > mydata = rnorm(length(sp), mean=m) > IDs = paste("ID",1:length(mydata)) > mydata = data.frame(values = signif(mydata,3),ID=IDs) > stidf = STIDF(sp, time, mydata) > stidf An object of class "STIDF" Slot "data": values ID 1 10.7 ID 1 2 19.8 ID 2 3 29.2 ID 3 4 41.8 ID 4 5 50.2 ID 5 6 59.9 ID 6 7 70.9 ID 7 8 80.0 ID 8 9 90.2 ID 9 Slot "sp": SpatialPoints: x y point1 1 1 point2 2 1 point3 3 1 point4 1 2 point5 2 2 point6 3 2 point7 1 3 point8 2 3 point9 3 3 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 11:00:00 1 2010-08-05 12:00:00 2 2010-08-05 13:00:00 3 2010-08-05 14:00:00 4 2010-08-05 15:00:00 5 2010-08-05 16:00:00 6 2010-08-05 17:00:00 7 2010-08-05 18:00:00 8 2010-08-05 19:00:00 9 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" "2010-08-05 12:00:00 GMT" [3] "2010-08-05 13:00:00 GMT" "2010-08-05 14:00:00 GMT" [5] "2010-08-05 15:00:00 GMT" "2010-08-05 16:00:00 GMT" [7] "2010-08-05 17:00:00 GMT" "2010-08-05 18:00:00 GMT" [9] "2010-08-05 19:00:00 GMT" > > > ################################################### > ### chunk number 12: > ################################################### > stidf[1:2,] An object of class "STIDF" Slot "data": values ID 1 10.7 ID 1 2 19.8 ID 2 Slot "sp": SpatialPoints: x y point1 1 1 point2 2 1 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 11:00:00 1 2010-08-05 12:00:00 2 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" "2010-08-05 12:00:00 GMT" > > > ################################################### > ### chunk number 13: > ################################################### > stfdf[,time[3]] coordinates values ID newVal NewID 1 (0, 0) 9.74 OldIDs10 -0.95252 NewIDs3 2 (0, 1) 20.70 OldIDs11 -1.69971 NewIDs2 3 (1, 1) 30.50 OldIDs12 0.89985 NewIDs1 > > > ################################################### > ### chunk number 14: > ################################################### > class(stfdf[,time[3],drop=FALSE]) [1] "STFDF" attr(,"package") [1] "spacetime" > > ################################################### > ### chunk number 15: > ################################################### > stfdf[1, , "values"] values timeIndex 2010-08-05 10:00:00 8.77 1 2010-08-05 11:00:00 8.47 2 2010-08-05 12:00:00 10.80 3 2010-08-05 13:00:00 9.74 4 > > ################################################### > ### chunk number 16: > ################################################### > class(stfdf[1,drop=FALSE]) [1] "STFDF" attr(,"package") [1] "spacetime" > > > ################################################### > ### chunk number 17: > ################################################### > class(stfdf) [1] "STFDF" attr(,"package") [1] "spacetime" > class(as(stfdf, "STSDF")) [1] "STSDF" attr(,"package") [1] "spacetime" > class(as(as(stfdf, "STSDF"), "STIDF")) [1] "STIDF" attr(,"package") [1] "spacetime" > class(as(stfdf, "STIDF")) [1] "STIDF" attr(,"package") [1] "spacetime" > > > ################################################### > ### chunk number 18: > ################################################### > x = as(stfdf, "STIDF") > class(as(x, "STSDF")) [1] "STSDF" attr(,"package") [1] "spacetime" > class(as(as(x, "STSDF"), "STFDF")) [1] "STFDF" attr(,"package") [1] "spacetime" > class(as(x, "STFDF")) [1] "STFDF" attr(,"package") [1] "spacetime" > xx = as(x, "STFDF") > identical(stfdf, xx) [1] TRUE > > stsdf = as(stfdf, "STSDF") > stsdf[[1]] [1] 8.77 18.70 29.70 8.47 21.10 32.50 10.80 20.20 29.00 9.74 20.70 30.50 > stsdf[["values"]] [1] 8.77 18.70 29.70 8.47 21.10 32.50 10.80 20.20 29.00 9.74 20.70 30.50 > stsdf[["newVal"]] <- rnorm(12) > stsdf$ID [1] "OldIDs1" "OldIDs2" "OldIDs3" "OldIDs4" "OldIDs5" "OldIDs6" [7] "OldIDs7" "OldIDs8" "OldIDs9" "OldIDs10" "OldIDs11" "OldIDs12" > stsdf$ID = paste("OldIDs", 1:12, sep="") > stsdf$NewID = paste("NewIDs", 12:1, sep="") > stsdf An object of class "STSDF" Slot "data": values ID newVal NewID 1 8.77 OldIDs1 -1.24345 NewIDs12 2 18.70 OldIDs2 -1.47698 NewIDs11 3 29.70 OldIDs3 -0.84284 NewIDs10 4 8.47 OldIDs4 1.54992 NewIDs9 5 21.10 OldIDs5 1.04955 NewIDs8 6 32.50 OldIDs6 1.35744 NewIDs7 7 10.80 OldIDs7 1.33925 NewIDs6 8 20.20 OldIDs8 0.77757 NewIDs5 9 29.00 OldIDs9 0.39454 NewIDs4 10 9.74 OldIDs10 0.15138 NewIDs3 11 20.70 OldIDs11 -0.38780 NewIDs2 12 30.50 OldIDs12 0.46815 NewIDs1 Slot "index": [,1] [,2] [1,] 1 1 [2,] 2 1 [3,] 3 1 [4,] 1 2 [5,] 2 2 [6,] 3 2 [7,] 1 3 [8,] 2 3 [9,] 3 3 [10,] 1 4 [11,] 2 4 [12,] 3 4 Slot "sp": SpatialPoints: x y point1 0 0 point2 0 1 point3 1 1 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 2010-08-05 11:00:00 2 2010-08-05 12:00:00 3 2010-08-05 13:00:00 4 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" "2010-08-05 12:00:00 GMT" [3] "2010-08-05 13:00:00 GMT" "2010-08-05 14:00:00 GMT" > stsdf[,1] # SpatialPointsDataFrame: coordinates values ID newVal NewID 1 (0, 0) 8.77 OldIDs1 -1.24345 NewIDs12 2 (0, 1) 18.70 OldIDs2 -1.47698 NewIDs11 3 (1, 1) 29.70 OldIDs3 -0.84284 NewIDs10 > stsdf[,,1] An object of class "STSDF" Slot "data": values 1 8.77 2 18.70 3 29.70 4 8.47 5 21.10 6 32.50 7 10.80 8 20.20 9 29.00 10 9.74 11 20.70 12 30.50 Slot "index": [,1] [,2] [1,] 1 1 [2,] 2 1 [3,] 3 1 [4,] 1 2 [5,] 2 2 [6,] 3 2 [7,] 1 3 [8,] 2 3 [9,] 3 3 [10,] 1 4 [11,] 2 4 [12,] 3 4 Slot "sp": SpatialPoints: x y point1 0 0 point2 0 1 point3 1 1 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 2010-08-05 11:00:00 2 2010-08-05 12:00:00 3 2010-08-05 13:00:00 4 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" "2010-08-05 12:00:00 GMT" [3] "2010-08-05 13:00:00 GMT" "2010-08-05 14:00:00 GMT" > stsdf[1,,1] # xts values timeIndex 2010-08-05 10:00:00 8.77 1 2010-08-05 11:00:00 8.47 2 2010-08-05 12:00:00 10.80 3 2010-08-05 13:00:00 9.74 4 > stsdf[,,"ID"] An object of class "STSDF" Slot "data": ID 1 OldIDs1 2 OldIDs2 3 OldIDs3 4 OldIDs4 5 OldIDs5 6 OldIDs6 7 OldIDs7 8 OldIDs8 9 OldIDs9 10 OldIDs10 11 OldIDs11 12 OldIDs12 Slot "index": [,1] [,2] [1,] 1 1 [2,] 2 1 [3,] 3 1 [4,] 1 2 [5,] 2 2 [6,] 3 2 [7,] 1 3 [8,] 2 3 [9,] 3 3 [10,] 1 4 [11,] 2 4 [12,] 3 4 Slot "sp": SpatialPoints: x y point1 0 0 point2 0 1 point3 1 1 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 2010-08-05 11:00:00 2 2010-08-05 12:00:00 3 2010-08-05 13:00:00 4 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" "2010-08-05 12:00:00 GMT" [3] "2010-08-05 13:00:00 GMT" "2010-08-05 14:00:00 GMT" > stsdf[1,,"values", drop=FALSE] # stays STIDF: An object of class "STSDF" Slot "data": values 1 8.77 4 8.47 7 10.80 10 9.74 Slot "index": [,1] [,2] [1,] 1 1 [2,] 1 2 [3,] 1 3 [4,] 1 4 Slot "sp": SpatialPoints: x y point1 0 0 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 2010-08-05 11:00:00 2 2010-08-05 12:00:00 3 2010-08-05 13:00:00 4 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" "2010-08-05 12:00:00 GMT" [3] "2010-08-05 13:00:00 GMT" "2010-08-05 14:00:00 GMT" > stsdf[,1, drop=FALSE] #stays STIDF An object of class "STSDF" Slot "data": values ID newVal NewID 1 8.77 OldIDs1 -1.24345 NewIDs12 2 18.70 OldIDs2 -1.47698 NewIDs11 3 29.70 OldIDs3 -0.84284 NewIDs10 Slot "index": [,1] [,2] [1,] 1 1 [2,] 2 1 [3,] 3 1 Slot "sp": SpatialPoints: x y point1 0 0 point2 0 1 point3 1 1 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" > format(as.data.frame(stsdf), tz="GMT") x y sp.ID time endTime timeIndex values ID 1 0 0 point1 2010-08-05 10:00:00 2010-08-05 11:00:00 1 8.77 OldIDs1 2 0 1 point2 2010-08-05 10:00:00 2010-08-05 11:00:00 1 18.70 OldIDs2 3 1 1 point3 2010-08-05 10:00:00 2010-08-05 11:00:00 1 29.70 OldIDs3 4 0 0 point1 2010-08-05 11:00:00 2010-08-05 12:00:00 2 8.47 OldIDs4 5 0 1 point2 2010-08-05 11:00:00 2010-08-05 12:00:00 2 21.10 OldIDs5 6 1 1 point3 2010-08-05 11:00:00 2010-08-05 12:00:00 2 32.50 OldIDs6 7 0 0 point1 2010-08-05 12:00:00 2010-08-05 13:00:00 3 10.80 OldIDs7 8 0 1 point2 2010-08-05 12:00:00 2010-08-05 13:00:00 3 20.20 OldIDs8 9 1 1 point3 2010-08-05 12:00:00 2010-08-05 13:00:00 3 29.00 OldIDs9 10 0 0 point1 2010-08-05 13:00:00 2010-08-05 14:00:00 4 9.74 OldIDs10 11 0 1 point2 2010-08-05 13:00:00 2010-08-05 14:00:00 4 20.70 OldIDs11 12 1 1 point3 2010-08-05 13:00:00 2010-08-05 14:00:00 4 30.50 OldIDs12 newVal NewID 1 -1.24345 NewIDs12 2 -1.47698 NewIDs11 3 -0.84284 NewIDs10 4 1.54992 NewIDs9 5 1.04955 NewIDs8 6 1.35744 NewIDs7 7 1.33925 NewIDs6 8 0.77757 NewIDs5 9 0.39454 NewIDs4 10 0.15138 NewIDs3 11 -0.38780 NewIDs2 12 0.46815 NewIDs1 > format(as(stsdf, "data.frame"), tz="GMT") x y sp.ID time endTime timeIndex values ID 1 0 0 point1 2010-08-05 10:00:00 2010-08-05 11:00:00 1 8.77 OldIDs1 2 0 1 point2 2010-08-05 10:00:00 2010-08-05 11:00:00 1 18.70 OldIDs2 3 1 1 point3 2010-08-05 10:00:00 2010-08-05 11:00:00 1 29.70 OldIDs3 4 0 0 point1 2010-08-05 11:00:00 2010-08-05 12:00:00 2 8.47 OldIDs4 5 0 1 point2 2010-08-05 11:00:00 2010-08-05 12:00:00 2 21.10 OldIDs5 6 1 1 point3 2010-08-05 11:00:00 2010-08-05 12:00:00 2 32.50 OldIDs6 7 0 0 point1 2010-08-05 12:00:00 2010-08-05 13:00:00 3 10.80 OldIDs7 8 0 1 point2 2010-08-05 12:00:00 2010-08-05 13:00:00 3 20.20 OldIDs8 9 1 1 point3 2010-08-05 12:00:00 2010-08-05 13:00:00 3 29.00 OldIDs9 10 0 0 point1 2010-08-05 13:00:00 2010-08-05 14:00:00 4 9.74 OldIDs10 11 0 1 point2 2010-08-05 13:00:00 2010-08-05 14:00:00 4 20.70 OldIDs11 12 1 1 point3 2010-08-05 13:00:00 2010-08-05 14:00:00 4 30.50 OldIDs12 newVal NewID 1 -1.24345 NewIDs12 2 -1.47698 NewIDs11 3 -0.84284 NewIDs10 4 1.54992 NewIDs9 5 1.04955 NewIDs8 6 1.35744 NewIDs7 7 1.33925 NewIDs6 8 0.77757 NewIDs5 9 0.39454 NewIDs4 10 0.15138 NewIDs3 11 -0.38780 NewIDs2 12 0.46815 NewIDs1 > > stidf = as(stfdf, "STIDF") > stidf[[1]] [1] 8.77 18.70 29.70 8.47 21.10 32.50 10.80 20.20 29.00 9.74 20.70 30.50 > stidf[["values"]] [1] 8.77 18.70 29.70 8.47 21.10 32.50 10.80 20.20 29.00 9.74 20.70 30.50 > stidf[["newVal"]] <- rnorm(12) > stidf$ID [1] "OldIDs1" "OldIDs2" "OldIDs3" "OldIDs4" "OldIDs5" "OldIDs6" [7] "OldIDs7" "OldIDs8" "OldIDs9" "OldIDs10" "OldIDs11" "OldIDs12" > stidf$ID = paste("OldIDs", 1:12, sep="") > stidf$NewID = paste("NewIDs", 12:1, sep="") > stidf An object of class "STIDF" Slot "data": values ID newVal NewID 1 8.77 OldIDs1 1.67415 NewIDs12 2 18.70 OldIDs2 -1.47819 NewIDs11 3 29.70 OldIDs3 -1.63290 NewIDs10 4 8.47 OldIDs4 -0.97491 NewIDs9 5 21.10 OldIDs5 -0.76499 NewIDs8 6 32.50 OldIDs6 0.10300 NewIDs7 7 10.80 OldIDs7 -1.06830 NewIDs6 8 20.20 OldIDs8 0.47947 NewIDs5 9 29.00 OldIDs9 1.17482 NewIDs4 10 9.74 OldIDs10 1.03354 NewIDs3 11 20.70 OldIDs11 0.82826 NewIDs2 12 30.50 OldIDs12 -0.75862 NewIDs1 Slot "sp": SpatialPoints: x y point1 0 0 point2 0 1 point3 1 1 point1.1 0 0 point2.1 0 1 point3.1 1 1 point1.2 0 0 point2.2 0 1 point3.2 1 1 point1.3 0 0 point2.3 0 1 point3.3 1 1 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 2010-08-05 10:00:00 1 2010-08-05 10:00:00 1 2010-08-05 11:00:00 2 2010-08-05 11:00:00 2 2010-08-05 11:00:00 2 2010-08-05 12:00:00 3 2010-08-05 12:00:00 3 2010-08-05 12:00:00 3 2010-08-05 13:00:00 4 2010-08-05 13:00:00 4 2010-08-05 13:00:00 4 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" "2010-08-05 11:00:00 GMT" [3] "2010-08-05 11:00:00 GMT" "2010-08-05 12:00:00 GMT" [5] "2010-08-05 12:00:00 GMT" "2010-08-05 12:00:00 GMT" [7] "2010-08-05 13:00:00 GMT" "2010-08-05 13:00:00 GMT" [9] "2010-08-05 13:00:00 GMT" "2010-08-05 14:00:00 GMT" [11] "2010-08-05 14:00:00 GMT" "2010-08-05 14:00:00 GMT" > stidf[,1] # SpatialPointsDataFrame: An object of class "STIDF" Slot "data": values ID newVal NewID 1 8.77 OldIDs1 1.6741 NewIDs12 Slot "sp": SpatialPoints: x y point1 0 0 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" > stidf[,,1] An object of class "STIDF" Slot "data": values 1 8.77 2 18.70 3 29.70 4 8.47 5 21.10 6 32.50 7 10.80 8 20.20 9 29.00 10 9.74 11 20.70 12 30.50 Slot "sp": SpatialPoints: x y point1 0 0 point2 0 1 point3 1 1 point1.1 0 0 point2.1 0 1 point3.1 1 1 point1.2 0 0 point2.2 0 1 point3.2 1 1 point1.3 0 0 point2.3 0 1 point3.3 1 1 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 2010-08-05 10:00:00 1 2010-08-05 10:00:00 1 2010-08-05 11:00:00 2 2010-08-05 11:00:00 2 2010-08-05 11:00:00 2 2010-08-05 12:00:00 3 2010-08-05 12:00:00 3 2010-08-05 12:00:00 3 2010-08-05 13:00:00 4 2010-08-05 13:00:00 4 2010-08-05 13:00:00 4 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" "2010-08-05 11:00:00 GMT" [3] "2010-08-05 11:00:00 GMT" "2010-08-05 12:00:00 GMT" [5] "2010-08-05 12:00:00 GMT" "2010-08-05 12:00:00 GMT" [7] "2010-08-05 13:00:00 GMT" "2010-08-05 13:00:00 GMT" [9] "2010-08-05 13:00:00 GMT" "2010-08-05 14:00:00 GMT" [11] "2010-08-05 14:00:00 GMT" "2010-08-05 14:00:00 GMT" > stidf[1,,1] # xts An object of class "STIDF" Slot "data": values 1 8.77 Slot "sp": SpatialPoints: x y point1 0 0 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" > stidf[,,"ID"] An object of class "STIDF" Slot "data": ID 1 OldIDs1 2 OldIDs2 3 OldIDs3 4 OldIDs4 5 OldIDs5 6 OldIDs6 7 OldIDs7 8 OldIDs8 9 OldIDs9 10 OldIDs10 11 OldIDs11 12 OldIDs12 Slot "sp": SpatialPoints: x y point1 0 0 point2 0 1 point3 1 1 point1.1 0 0 point2.1 0 1 point3.1 1 1 point1.2 0 0 point2.2 0 1 point3.2 1 1 point1.3 0 0 point2.3 0 1 point3.3 1 1 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 2010-08-05 10:00:00 1 2010-08-05 10:00:00 1 2010-08-05 11:00:00 2 2010-08-05 11:00:00 2 2010-08-05 11:00:00 2 2010-08-05 12:00:00 3 2010-08-05 12:00:00 3 2010-08-05 12:00:00 3 2010-08-05 13:00:00 4 2010-08-05 13:00:00 4 2010-08-05 13:00:00 4 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" "2010-08-05 11:00:00 GMT" [3] "2010-08-05 11:00:00 GMT" "2010-08-05 12:00:00 GMT" [5] "2010-08-05 12:00:00 GMT" "2010-08-05 12:00:00 GMT" [7] "2010-08-05 13:00:00 GMT" "2010-08-05 13:00:00 GMT" [9] "2010-08-05 13:00:00 GMT" "2010-08-05 14:00:00 GMT" [11] "2010-08-05 14:00:00 GMT" "2010-08-05 14:00:00 GMT" > stidf[1,,"values", drop=FALSE] # stays STIDF: An object of class "STIDF" Slot "data": values 1 8.77 Slot "sp": SpatialPoints: x y point1 0 0 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" > stidf[,1, drop=FALSE] #stays STIDF An object of class "STIDF" Slot "data": values ID newVal NewID 1 8.77 OldIDs1 1.6741 NewIDs12 Slot "sp": SpatialPoints: x y point1 0 0 Coordinate Reference System (CRS) arguments: NA Slot "time": timeIndex 2010-08-05 10:00:00 1 Slot "endTime": [1] "2010-08-05 11:00:00 GMT" > format(as.data.frame(stidf), tz="GMT") x y sp.ID time endTime timeIndex values 1 0 0 point1 2010-08-05 10:00:00 2010-08-05 11:00:00 1 8.77 2 0 1 point2 2010-08-05 10:00:00 2010-08-05 11:00:00 1 18.70 3 1 1 point3 2010-08-05 10:00:00 2010-08-05 11:00:00 1 29.70 4 0 0 point1.1 2010-08-05 11:00:00 2010-08-05 12:00:00 2 8.47 5 0 1 point2.1 2010-08-05 11:00:00 2010-08-05 12:00:00 2 21.10 6 1 1 point3.1 2010-08-05 11:00:00 2010-08-05 12:00:00 2 32.50 7 0 0 point1.2 2010-08-05 12:00:00 2010-08-05 13:00:00 3 10.80 8 0 1 point2.2 2010-08-05 12:00:00 2010-08-05 13:00:00 3 20.20 9 1 1 point3.2 2010-08-05 12:00:00 2010-08-05 13:00:00 3 29.00 10 0 0 point1.3 2010-08-05 13:00:00 2010-08-05 14:00:00 4 9.74 11 0 1 point2.3 2010-08-05 13:00:00 2010-08-05 14:00:00 4 20.70 12 1 1 point3.3 2010-08-05 13:00:00 2010-08-05 14:00:00 4 30.50 ID newVal NewID 1 OldIDs1 1.67415 NewIDs12 2 OldIDs2 -1.47819 NewIDs11 3 OldIDs3 -1.63290 NewIDs10 4 OldIDs4 -0.97491 NewIDs9 5 OldIDs5 -0.76499 NewIDs8 6 OldIDs6 0.10300 NewIDs7 7 OldIDs7 -1.06830 NewIDs6 8 OldIDs8 0.47947 NewIDs5 9 OldIDs9 1.17482 NewIDs4 10 OldIDs10 1.03354 NewIDs3 11 OldIDs11 0.82826 NewIDs2 12 OldIDs12 -0.75862 NewIDs1 > format(as(stidf, "data.frame"), tz="GMT") x y sp.ID time endTime timeIndex values 1 0 0 point1 2010-08-05 10:00:00 2010-08-05 11:00:00 1 8.77 2 0 1 point2 2010-08-05 10:00:00 2010-08-05 11:00:00 1 18.70 3 1 1 point3 2010-08-05 10:00:00 2010-08-05 11:00:00 1 29.70 4 0 0 point1.1 2010-08-05 11:00:00 2010-08-05 12:00:00 2 8.47 5 0 1 point2.1 2010-08-05 11:00:00 2010-08-05 12:00:00 2 21.10 6 1 1 point3.1 2010-08-05 11:00:00 2010-08-05 12:00:00 2 32.50 7 0 0 point1.2 2010-08-05 12:00:00 2010-08-05 13:00:00 3 10.80 8 0 1 point2.2 2010-08-05 12:00:00 2010-08-05 13:00:00 3 20.20 9 1 1 point3.2 2010-08-05 12:00:00 2010-08-05 13:00:00 3 29.00 10 0 0 point1.3 2010-08-05 13:00:00 2010-08-05 14:00:00 4 9.74 11 0 1 point2.3 2010-08-05 13:00:00 2010-08-05 14:00:00 4 20.70 12 1 1 point3.3 2010-08-05 13:00:00 2010-08-05 14:00:00 4 30.50 ID newVal NewID 1 OldIDs1 1.67415 NewIDs12 2 OldIDs2 -1.47819 NewIDs11 3 OldIDs3 -1.63290 NewIDs10 4 OldIDs4 -0.97491 NewIDs9 5 OldIDs5 -0.76499 NewIDs8 6 OldIDs6 0.10300 NewIDs7 7 OldIDs7 -1.06830 NewIDs6 8 OldIDs8 0.47947 NewIDs5 9 OldIDs9 1.17482 NewIDs4 10 OldIDs10 1.03354 NewIDs3 11 OldIDs11 0.82826 NewIDs2 12 OldIDs12 -0.75862 NewIDs1 > > sp = cbind(x = c(0,0,1), y = c(0,1,1)) > row.names(sp) = paste("point", 1:nrow(sp), sep="") > sp = SpatialPoints(sp) > library(xts) Loading required package: zoo Attaching package: 'zoo' The following objects are masked from 'package:base': as.Date, as.Date.numeric > time = xts(1:4, as.POSIXct("2010-08-05", tz="GMT")+3600*(10:13)) > mydata = rnorm(length(sp)*length(time),mean=rep(m, 4)) > IDs = paste("ID", 1:length(mydata), sep = "_") > mydata = data.frame(values = signif(mydata,3), ID=IDs) > spx = SpatialPointsDataFrame(sp, data.frame(values = c("a", "b", "c"))) > try(stfdf <- STFDF(spx, time, mydata)) Error in .checkAttrIsUnique(object@sp, object@time, object@data) : name conflict: attribute name(s) in data already present in sp slot of ST object > timex = time > names(timex) = "values" > try(stfdf <- STFDF(sp, timex, mydata)) Error in .checkAttrIsUnique(object@sp, object@time, object@data) : name conflict: attribute name(s) in data already present in time slot of ST object > mydatax = mydata > names(mydatax) = "x" > try(stfdf <- STFDF(spx, timex, mydatax)) Error in validityMethod(object) : name conflict: attribute names in sp and time slot must differ > stfdf = STFDF(sp, timex, mydatax) > try(stfdf[["values"]] <- 1:12) Error in .checkAttrIsUnique(x@sp, x@time, x@data) : name conflict: attribute name(s) in data already present in time slot of ST object > stfdf = STFDF(spx, time, mydatax) > try(stfdf[["values"]] <- 1:12) Error in .checkAttrIsUnique(x@sp, x@time, x@data) : name conflict: attribute name(s) in data already present in sp slot of ST object > > proc.time() user system elapsed 1.03 0.09 1.10