#' Filter data with time interval
#'
#' @description Filter radiotracking data with start and end time
#'
#' @param data data.frame of radiotrackin data
#' @param time_distance vector with two POSIXct times
#'
#' @return data.frame of filtered radiotracking data
#'
#' @author RadioTracking EU
#'
#' @export
filter_data_time_interval <- function(data,time_distance){
#find for each receiver
list_of_receivers<-unique(data$receiver)
#and each frequency
list_of_frequencies<-unique(data$freq_tag)
#signals which appear betweeen time_distance[1] and time_distance[2] seconds
return_tmp<-NULL
for(i in list_of_receivers){
tmp1 <- subset(data,receiver==i)
for(k in list_of_frequencies){
tmp2<-subset(tmp1,freq_tag==k)
tmp2<-tmp2[order(tmp2$timestamp),]
#calcualte the time distance between the impulses
if(nrow(tmp2)>1){
td<-diff(tmp2$timestamp)
if(attr(td,"units")=="secs"){
td<-c(td,td[length(td)])
tmp2<-cbind(tmp2,td=td)
test<-tmp2$td>time_distance[1]&tmp2$td<time_distance[2]
i<-1
while(i<length(test)-1){
if(!test[i+1]&&test[i]){
test[i+1]<-TRUE
i<-i+1
}
i<-i+1
}
tmp2<-tmp2[test,]
return_tmp<-rbind(tmp2,return_tmp)
}
}
}
}
return(return_tmp)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.