Skip to contents

get_gbi generates a group by individual matrix. The function expects 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

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.

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.

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')]
#>            ID        X       Y            datetime population
#>        <char>    <num>   <num>              <POSc>      <int>
#>     1:      A 715851.4 5505340 2016-11-01 00:00:54          1
#>     2:      A 715822.8 5505289 2016-11-01 02:01:22          1
#>     3:      A 715872.9 5505252 2016-11-01 04:01:24          1
#>     4:      A 715820.5 5505231 2016-11-01 06:01:05          1
#>     5:      A 715830.6 5505227 2016-11-01 08:01:11          1
#>    ---                                                       
#> 14293:      J 700616.5 5509069 2017-02-28 14:00:54          1
#> 14294:      J 700622.6 5509065 2017-02-28 16:00:11          1
#> 14295:      J 700657.5 5509277 2017-02-28 18:00:55          1
#> 14296:      J 700610.3 5509269 2017-02-28 20:00:48          1
#> 14297:      J 700744.0 5508782 2017-02-28 22:00:39          1
DT[, yr := year(datetime)]
#>            ID        X       Y            datetime population    yr
#>        <char>    <num>   <num>              <POSc>      <int> <int>
#>     1:      A 715851.4 5505340 2016-11-01 00:00:54          1  2016
#>     2:      A 715822.8 5505289 2016-11-01 02:01:22          1  2016
#>     3:      A 715872.9 5505252 2016-11-01 04:01:24          1  2016
#>     4:      A 715820.5 5505231 2016-11-01 06:01:05          1  2016
#>     5:      A 715830.6 5505227 2016-11-01 08:01:11          1  2016
#>    ---                                                             
#> 14293:      J 700616.5 5509069 2017-02-28 14:00:54          1  2017
#> 14294:      J 700622.6 5509065 2017-02-28 16:00:11          1  2017
#> 14295:      J 700657.5 5509277 2017-02-28 18:00:55          1  2017
#> 14296:      J 700610.3 5509269 2017-02-28 20:00:48          1  2017
#> 14297:      J 700744.0 5508782 2017-02-28 22:00:39          1  2017

# 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')
#>            ID        X       Y            datetime population    yr group
#>        <char>    <num>   <num>              <POSc>      <int> <int> <int>
#>     1:      A 715851.4 5505340 2016-11-01 00:00:54          1  2016     1
#>     2:      A 715822.8 5505289 2016-11-01 02:01:22          1  2016     1
#>     3:      A 715872.9 5505252 2016-11-01 04:01:24          1  2016     1
#>     4:      A 715820.5 5505231 2016-11-01 06:01:05          1  2016     1
#>     5:      A 715830.6 5505227 2016-11-01 08:01:11          1  2016     1
#>    ---                                                                   
#> 14293:      J 700616.5 5509069 2017-02-28 14:00:54          1  2017     2
#> 14294:      J 700622.6 5509065 2017-02-28 16:00:11          1  2017     2
#> 14295:      J 700657.5 5509277 2017-02-28 18:00:55          1  2017     2
#> 14296:      J 700610.3 5509269 2017-02-28 20:00:48          1  2017     2
#> 14297:      J 700744.0 5508782 2017-02-28 22:00:39          1  2017     2

gbiMtrx <- get_gbi(DT = DT, group = 'group', id = 'ID')