layer_neighbors: Neighbourhood

Description Usage Arguments Value Examples

View source: R/metrics.R

Description

Number of neighbors adjacent to each actor. Calculated excluding self from set of neighbors.

Usage

1
layer_neighbors(DT, id, splitBy = NULL)

Arguments

DT

a data.table with column "group" generated by spatsoc::group_pts

id
splitBy

the column which defines the layers of the network

Value

The input DT with additional column "neigh" and optionally "splitNeigh" if a column was provided for the 'splitBy' argument.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# Load data.table and spatsoc
library(data.table)
library(spatsoc)

# Read example data
DT <- fread(system.file("extdata", "DT.csv", package = "spatsoc"))

# Cast the character column to POSIXct
DT[, datetime := as.POSIXct(datetime, tz = 'UTC')]

# Temporal grouping
group_times(DT, datetime = 'datetime', threshold = '20 minutes')

# Spatial grouping with timegroup
group_pts(DT, threshold = 5, id = 'ID',
          coords = c('X', 'Y'), timegroup = 'timegroup')
          
# Pseudo-season
DT[, season := sample(c(1, 2), .N, replace = TRUE)]

layer_neighbors(DT, 'ID', splitBy = 'season')

robitalec/ScaleInMultilayerNetworks documentation built on Dec. 22, 2021, 5:14 p.m.