Insert NA gaps to regularize a time series

insert_NAs(data, int, units)



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.


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


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


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[-ind,] #calculate step lengths, turning angles, net-squared displacement, and time steps<- prep_data(dat =, coord.names = c("x","y"), id = "id") #round times to nearest interval<- round_track_time(dat =, id = "id", int = c(3600, 7200, 10800, 14400), tol = 300, units = "secs") #insert NA gaps dat.out<- insert_NAs(, int = 3600, units = "secs")