get_gbi {spatsoc} | R Documentation |
Generate group by individual matrix
Description
get_gbi
generates a group by individual matrix. The function accepts a
data.table
with individual identifiers and a group column. The group
by individual matrix can then be used to build a network using
asnipe::get_network
.
Usage
get_gbi(DT = NULL, group = "group", id = NULL)
Arguments
DT |
input data.table |
group |
Character string of group column (generated from one of spatsoc's spatial grouping functions) |
id |
Character string of ID column name |
Details
The DT
must be a data.table
. If your data is a
data.frame
, you can convert it by reference using
data.table::setDT
.
The group
argument expects the name of a column which corresponds to
an integer group identifier (generated by spatsoc
's grouping
functions).
The id
argument expects the name of a column which corresponds to the
individual identifier.
Value
get_gbi
returns a group by individual matrix (columns
represent individuals and rows represent groups).
Note that get_gbi
is identical in function for turning the outputs
of spatsoc
into social networks as
asnipe::get_group_by_individual
but is more efficient thanks to
data.table::dcast
.
See Also
group_pts
group_lines
group_polys
Other Social network tools:
randomizations()
Examples
# Load data.table
library(data.table)
# 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')]
DT[, yr := year(datetime)]
# EPSG code for example data
utm <- 'EPSG:32736'
group_polys(DT, area = FALSE, hrType = 'mcp',
hrParams = list(percent = 95),
projection = utm, id = 'ID', coords = c('X', 'Y'),
splitBy = 'yr')
gbiMtrx <- get_gbi(DT = DT, group = 'group', id = 'ID')