Insert NA gaps to regularize a time series
insert_NAs(data, int, units)
data | A data frame that minimally contains columns for animal ID, date,
and time step. These must be labeled |
---|---|
int | integer. An integer that characterizes the desired interval on which to insert new rows. |
units | character. The units of the selected time interval |
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.
#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")