File: basic.Rout.save

package info (click to toggle)
r-cran-spacetime 1.2-4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,308 kB
  • sloc: sh: 13; makefile: 2
file content (1127 lines) | stat: -rw-r--r-- 31,512 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127

R version 3.2.2 (2015-08-14) -- "Fire Safety"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

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  ID_10 ID_11 ID_12
Levels: ID_1 ID_10 ID_11 ID_12 ID_2 ID_3 ID_4 ID_5 ID_6 ID_7 ID_8 ID_9
> 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 
  0.828   0.316   0.832