View source: R/centroid_group.R
centroid_group | R Documentation |
centroid_group
calculates the centroid (mean location) of all
individuals in each spatiotemporal group identified by group_pts
. The
function accepts a data.table
with relocation data appended with a
group
column from group_pts
. Relocation data should be in two
columns representing the X and Y coordinates.
centroid_group(DT = NULL, coords = NULL, group = "group", na.rm = FALSE)
DT |
input data.table with group column generated with |
coords |
character vector of X coordinate and Y coordinate column names. Note: the order is assumed X followed by Y column names. |
group |
Character string of group column |
na.rm |
if NAs should be removed in calculating mean location, see |
The DT
must be a data.table
. If your data is a
data.frame
, you can convert it by reference using
data.table::setDT
or by reassigning using
data.table::data.table
.
The coords
and group
arguments expect the names of a column in
DT
which correspond to the X and Y coordinates and group columns. The
na.rm
argument is passed to the mean
function to control if NA
values are removed before calculation.
centroid_group
returns the input DT
appended with
centroid columns for the X and Y coordinate columns.
These columns represents the centroid coordinate columns. The naming of these columns will correspond to the provided coordinate column names prefixed with "centroid_".
A message is returned when centroid columns are already exists in
the input DT
, because they will be overwritten.
group_pts
Other Centroid functions:
centroid_dyad()
,
centroid_fusion()
# 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')]
# 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')
# Calculate group centroid
centroid_group(DT, coords = c('X', 'Y'), group = 'group', na.rm = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.