insert_NAs: Insert NA gaps to regularize a time series

Description Usage Arguments Value Examples

View source: R/segmentation_helper_functions.R

Description

Insert NA gaps to regularize a time series

Usage

1

Arguments

data

A data frame that minimally contains columns for animal ID, date, and time step. These must be labeled id, date, and dt, respectively, where date is of class POSIXct.

int

integer. An integer that characterizes the desired interval on which to insert new rows.

units

character. The units of the selected time interval int, which can be selected from one of "secs", "mins", "hours", "days", or "weeks".

Value

A data frame where new rows have been inserted to regularize the date column. This results in values provided for id, date, and dt while inserting NAs for all other columns. Additionally, observations with duplicate date-times are removed.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#load data
data(tracks)

#remove rows to show how function works (create irregular time series)
set.seed(1)
ind<- sort(sample(2:15003, 500))

tracks.red<- tracks[-ind,]

#calculate step lengths, turning angles, net-squared displacement, and time steps
tracks.red<- prep_data(dat = tracks.red, coord.names = c("x","y"), id = "id")

#round times to nearest interval
tracks.red<- round_track_time(dat = tracks.red, id = "id", int = c(3600, 7200, 10800, 14400),
                              tol = 300, units = "secs")

#insert NA gaps
dat.out<- insert_NAs(tracks.red, int = 3600, units = "secs")

bayesmove documentation built on Oct. 22, 2021, 9:08 a.m.