diff --git a/NAMESPACE b/NAMESPACE index ba4c7247..50f26890 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ export(build_polys) export(centroid_dyad) export(centroid_fusion) export(centroid_group) +export(direction_group) export(direction_step) export(direction_to_centroid) export(distance_to_centroid) diff --git a/man/centroid_dyad.Rd b/man/centroid_dyad.Rd index 74f69d35..9e7a7368 100644 --- a/man/centroid_dyad.Rd +++ b/man/centroid_dyad.Rd @@ -81,9 +81,6 @@ library(data.table) # Read example data DT <- fread(system.file("extdata", "DT.csv", package = "spatsoc")) -# Select only individuals A, B, C for this example -DT <- DT[ID \%in\% c('A', 'B', 'C')] - # Cast the character column to POSIXct DT[, datetime := as.POSIXct(datetime, tz = 'UTC')] diff --git a/man/centroid_fusion.Rd b/man/centroid_fusion.Rd index 2c67b6a8..699c68f6 100644 --- a/man/centroid_fusion.Rd +++ b/man/centroid_fusion.Rd @@ -83,9 +83,6 @@ library(data.table) # Read example data DT <- fread(system.file("extdata", "DT.csv", package = "spatsoc")) -# Select only individuals A, B, C for this example -DT <- DT[ID \%in\% c('A', 'B', 'C')] - # Cast the character column to POSIXct DT[, datetime := as.POSIXct(datetime, tz = 'UTC')] diff --git a/man/centroid_group.Rd b/man/centroid_group.Rd index 4805aabe..2665967e 100644 --- a/man/centroid_group.Rd +++ b/man/centroid_group.Rd @@ -53,9 +53,6 @@ library(data.table) # Read example data DT <- fread(system.file("extdata", "DT.csv", package = "spatsoc")) -# Select only individuals A, B, C for this example -DT <- DT[ID \%in\% c('A', 'B', 'C')] - # Cast the character column to POSIXct DT[, datetime := as.POSIXct(datetime, tz = 'UTC')] diff --git a/man/direction_group.Rd b/man/direction_group.Rd new file mode 100644 index 00000000..240404c4 --- /dev/null +++ b/man/direction_group.Rd @@ -0,0 +1,90 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/direction_group.R +\name{direction_group} +\alias{direction_group} +\title{Group mean direction} +\usage{ +direction_group(DT, direction = "direction", group = "group") +} +\arguments{ +\item{DT}{input data.table with distance column generated by +\code{distance_step} and group column generated with \code{group_pts}} + +\item{direction}{character string of direction column name, default +"direction"} + +\item{group}{character string of group column name, default "group"} +} +\value{ +\code{direction_group} returns the input \code{DT} appended with a +\code{group_direction} column representing the mean direction of +all individuals in each spatiotemporal group. + +The mean direction is calculated using \code{\link{CircStats::circ.mean}} +which expects units of radians. + +A message is returned when the \code{group_direction} columns already +exists in the input \code{DT}, because it will be overwritten. +} +\description{ +\code{direction_group} calculates the mean direction of all individuals in +each spatiotemporal group identified by \code{group_pts}. The function +accepts a \code{data.table} with relocation data appended with a +\code{direction} column from \code{direction_step} and a \code{group} column +from \code{group_pts}. +} +\details{ +The \code{DT} must be a \code{data.table}. If your data is a +\code{data.frame}, you can convert it by reference using +\code{\link[data.table:setDT]{data.table::setDT}} or by reassigning using +\code{\link[data.table:data.table]{data.table::data.table}}. + +The \code{direction} and \code{group} arguments expect the names of columns +in \code{DT} which correspond to the direction and group columns. The +direction column is expected in units of radians and the mean calculated with +\code{\link{CircStats::circ.mean}}. +} +\examples{ +# Load data.table +library(data.table) +\dontshow{data.table::setDTthreads(1)} + +# 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) +} +\references{ +See example of using mean group direction: +\itemize{ +\item \url{https://doi.org/10.1098/rsos.170148} +\item \url{https://doi.org/10.1098/rsos.201128} +\item \url{https://doi.org/10.1016/j.beproc.2018.01.013} +} +} +\seealso{ +\code{\link{direction_step}}, \code{\link{group_pts}} + +Other Direction functions: +\code{\link{direction_step}()} +} +\concept{Direction functions} diff --git a/man/direction_step.Rd b/man/direction_step.Rd index 9d59134b..0b6df87c 100644 --- a/man/direction_step.Rd +++ b/man/direction_step.Rd @@ -97,5 +97,8 @@ direction_step( } \seealso{ \code{\link[amt:steps]{amt::direction_abs()}}, \code{\link[geosphere:bearing]{geosphere::bearing()}} + +Other Direction functions: +\code{\link{direction_group}()} } \concept{Direction functions}