View source: R/direction_group.R
direction_group | R Documentation |
direction_group
calculates the mean direction of all individuals in
each spatiotemporal group identified by group_pts
. The function
accepts a data.table
with relocation data appended with a
direction
column from direction_step
and a group
column
from group_pts
.
direction_group(DT, direction = "direction", group = "group")
DT |
input data.table with direction column generated by
|
direction |
character string of direction column name, default "direction" |
group |
character string of group column name, default "group" |
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 direction
and group
arguments expect the names of columns
in DT
which correspond to the direction and group columns. The
direction column is expected in units of radians and the mean calculated with
CircStats::circ.mean()
.
direction_group
returns the input DT
appended with a
group_direction
column representing the mean direction of
all individuals in each spatiotemporal group.
The mean direction is calculated using CircStats::circ.mean()
which expects units of radians.
A message is returned when the group_direction
columns already
exists in the input DT
, because it will be overwritten.
See examples of using mean group direction:
direction_step
, group_pts
,
CircStats::circ.mean()
Other Direction functions:
direction_polarization()
,
direction_step()
,
direction_to_leader()
,
edge_delay()
# 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 = 50, id = 'ID',
coords = c('X', 'Y'), timegroup = 'timegroup')
# Calculate direction at each step
direction_step(
DT = DT,
id = 'ID',
coords = c('X', 'Y'),
projection = 32736
)
# Calculate group direction
direction_group(DT)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.