# Assignment: don't print
a = 3
# No assignment: print
a[1] 3
# Interactive exploration
sqrt(a)[1] 1.732051
Analysis of Spatiotemporal Data - Session 1
2026-11-06
Advantages
Key Packages
sf - simple featuresterra - raster datastars - spatiotemporal arraystidyverse - data wranglingBook reference: r-spatial.org/book - Chapters 1-3, 5-8
Read - Evaluate - Print - Loop
Traditional nesting:
Read as: “Take 3:7, then sum, then sqrt, then sin”
Not only the language objects or functions, but basic “things” such as data objects.
Access elements using [ for ranges or [[ for single elements:
n*n array
Using rbind (bindig by rows)/cbind (binding by columns)
Most common data structure - like a spreadsheet!
Key Properties:
'data.frame': 3 obs. of 3 variables:
$ name : chr "Alice" "Bob" "Carol"
$ age : num 25 30 28
$ score: num 85.5 92 88.3
[1] "Alice" "Bob" "Carol"
[1] 25 30 28
Two dimensions: [rows, columns]
name age score
1 Alice 25 85.5
[1] 25 30 28
Matrix - All elements same type - Numeric operations - Homogeneous
data.frame operations work!ISO/OGC Standard
In R: sf package
Book reference: Chapter 1 - Getting Started
Simple feature collection with 100 features and 14 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
Geodetic CRS: NAD27
# A tibble: 100 × 15
AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO CRESS_ID BIR74 SID74 NWBIR74
<dbl> <dbl> <dbl> <dbl> <chr> <chr> <dbl> <int> <dbl> <dbl> <dbl>
1 0.114 1.44 1825 1825 Ashe 37009 37009 5 1091 1 10
2 0.061 1.23 1827 1827 Alle… 37005 37005 3 487 0 10
3 0.143 1.63 1828 1828 Surry 37171 37171 86 3188 5 208
4 0.07 2.97 1831 1831 Curr… 37053 37053 27 508 1 123
5 0.153 2.21 1832 1832 Nort… 37131 37131 66 1421 9 1066
6 0.097 1.67 1833 1833 Hert… 37091 37091 46 1452 7 954
7 0.062 1.55 1834 1834 Camd… 37029 37029 15 286 0 115
8 0.091 1.28 1835 1835 Gates 37073 37073 37 420 0 254
9 0.118 1.42 1836 1836 Warr… 37185 37185 93 968 4 748
10 0.124 1.43 1837 1837 Stok… 37169 37169 85 1612 1 160
# ℹ 90 more rows
# ℹ 4 more variables: BIR79 <dbl>, SID79 <dbl>, NWBIR79 <dbl>,
# geom <MULTIPOLYGON [°]>
Works seamlessly!
Simple feature collection with 3 features and 2 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -80.96577 ymin: 36.16217 xmax: -78.28293 ymax: 36.56521
Geodetic CRS: NAD27
# A tibble: 3 × 3
NAME BIR74 geom
<chr> <dbl> <MULTIPOLYGON [°]>
1 Surry 3188 (((-80.45634 36.24256, -80.47639 36.25473, -80.53688 36.2567…
2 Rockingham 4449 (((-79.53051 36.24614, -79.53058 36.23616, -80.02567 36.2502…
3 Vance 2180 (((-78.49252 36.17359, -78.51472 36.17522, -78.51709 36.4614…
SID74 > 10BIR74 / BIR79Concept: Space × Time
Packages:
starsspacetimeSimple feature collection with 3 features and 4 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -81.74107 ymin: 36.23388 xmax: -80.43531 ymax: 36.58965
Geodetic CRS: NAD27
# A tibble: 3 × 5
NAME BIR74 SID74 geom year
<chr> <dbl> <dbl> <MULTIPOLYGON [°]> <dbl>
1 Ashe 1091 1 (((-81.47276 36.23436, -81.54084 36.27251, -81.56… 1974
2 Alleghany 487 0 (((-81.23989 36.36536, -81.24069 36.37942, -81.26… 1974
3 Surry 3188 5 (((-80.45634 36.24256, -80.47639 36.25473, -80.53… 1974
Geometric Operations
st_buffer() - create buffersst_intersection() - overlapst_union() - mergest_centroid() - centersPredicates
st_intersects() - touches?st_within() - inside?st_distance() - how far?Primary
vignette(package="sf")Documentation
?st_read?st_transform?plot.sfPractice
R fundamentals: pipes, objects, workflow
Simple features: sf package, geometry types
Loading and plotting spatial data
CRS and transformations
Introduction to spatiotemporal data
Questions before exercises?
Next Hour:
Don’t hesitate to ask questions!
Geographic data introduction https://r.geocompx.org/spatial-class
Mastering R https://r4ds.hadley.nz/