# Load data.table
library(data.table)
data.table::setDTthreads(1)
# Read example data
DT <- fread(system.file("extdata", "DT.csv", package = "spatsoc"))
# Select only individuals A, B, C for this example
DT <- DT[ID %in% c('A', 'B', 'C')]
# Cast the character column to POSIXct
DT[, datetime := as.POSIXct(datetime, tz = 'UTC')]
# Temporal grouping
group_times(DT, datetime = 'datetime', threshold = '20 minutes')
# Edge list generation
edges <- edge_nn(DT, id = 'ID', coords = c('X', 'Y'),
timegroup = 'timegroup')
# Edge list generation using maximum distance threshold
edges <- edge_nn(DT, id = 'ID', coords = c('X', 'Y'),
timegroup = 'timegroup', threshold = 100)
# Edge list generation, returning distance between nearest neighbours
edge_nn(DT, id = 'ID', coords = c('X', 'Y'),
timegroup = 'timegroup', threshold = 100,
returnDist = TRUE)
Run the code above in your browser using DataLab