[R-sig-eco] segmenting (split) ltraj objects (adehabitatLT) into 10 day bursts

Christoph Eberhard Freiherr von Redwitz christoph.redwitz at uni-rostock.de
Tue Aug 12 16:08:19 CEST 2014


Ahoi again!
I am not sure, if this works exactly as you wish, but maybe it helps:


#this function gives TRUE for the first observation on each day when a new 10 days sequence starts
foo3 <- function(date) {
     tmp <- as.Date(date)             #in this format i can add 10 days without problems
     tmp1 <- date                     #to develop the function
     days <- levels(as.factor(tmp))   #what days do we have?
     sel_int <- rep(F,length(days))   #vector creation to mark the time steps (in the days)
     mark <- seq(1,length(sel),10)    #10 days sequece
     sel_int[mark] <- T               #all 10 days we have a TRUE
     sel_ext <-  rep(F,length(date))  #the marked vektor to start the new burst
     first_on_this_day <- c()
     for(i in 1:length(days)){
           first_on_this_day <- min(tmp1[tmp==days[sel_int][i]])
           sel_ext[which(tmp1==first_on_this_day)] <- T         #mark on the first observation on that day
     }

     return(sel_ext)
}
cltr2<-cutltraj(ltr1,"foo3(date)",nextr=F)





-----Ursprüngliche Nachricht-----
Von: r-sig-ecology-bounces at r-project.org [mailto:r-sig-ecology-bounces at r-project.org] Im Auftrag von Don Carlos
Gesendet: Samstag, 9. August 2014 13:09
An: r-sig-ecology at r-project.org
Betreff: [R-sig-eco] segmenting (split) ltraj objects (adehabitatLT) into 10 day bursts

Dear list,

I have been trying to find a way to segment (split) ltraj into regular bursts according to a temporal window (i.e. bursts containing 10 days of relocations).

The conceptual way I thought to implement this was to 1) extract the start date and end date from the ltraj summary list for each burst (bursts have varying start and end dates), 2)  for each of these vectors create a sequence (seq) using start and end dates and defining a 10 day interval, 3) use this to in conjunction with cutltraj to cut ltraj into 10 day segments.

I have not succeed in implementing this but below a reproducible example taken from the LT package and the steps as outlined. Any suggestions or pointers much appreciated.

install.packages("adehabitatLT")
data(capreochiz)
ltr1<- as.ltraj(xy = capreochiz[,c("x","y")],
                date = capreochiz$date,
                id = "Roe.Deer", typeII = TRUE,
                infolocs = capreochiz[,4:8])

sum<-summary(ltr1)

#extracting the min and max dates per burst (in this example #only one but often many bursts per ltraj. Ideally bound.dates #should round date.start and date.end up or down to the start of #the day and end of the day

bound.dates <- seq(min(sum$date.begin)-1,max(sum$date.end)+1,by="day")

#Below ideally what I would like to do but obviously not working

#as "bound.dates" not a logical expression. How could one #be constructed?

cltr1<-cutltraj(ltr1,"bound.dates",nextr=TRUE)

	[[alternative HTML version deleted]]

_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology



More information about the R-sig-ecology mailing list