I have a zoo object that contains velocity data from two different points (V1 and V2), as well as particle Data from the same two points. The distance between the two points is 170m.
Date<- as.POSIXct("2012-01-01 08:00:00") + 1:120
V1<-rnorm(200,mean=5) #Velocity in m/sec
R<-rnorm(4,mean=3)
V2<-V1+R #Velocity in m/sec
Data1<-rnorm(200, mean=20)
Data2<-rnorm(200, mean=25)
V<-data.frame(V1,V2,Data1,Data2)
z<-zoo(as.matrix(V),order.by=Date)
L<-170 #Length =170m
If I average the velocity data
z$Avg_Vel<-rowMeans(z[,1:2])
I should have a pretty good idea of how fast the particles are traveling, and since I know the distance I should have a good idea of how long it is taking the particles to travel from Point 1 to Point 2 during the course of the time series.
z$Off<-L/z$Avg_Vel
But I cant figure out how to offset my zoo object to account for the time delay it takes for particles to travel between the two points. So if I am interested in finding the difference between Data 1 and Data 2, I don't want to do
Diff<-z$Data1-z$Data2
As this does not include the offset
If it takes 2 minutes for the particles to travel from point 1 to point 2, than I would want
Diff<-z$Data1-z$Data2(+2min)
So that I am looking at the difference between Data1 at time x, and Data2 at time x+2min
To clarify in response to an answer, the end result would be a rolling offset. So that
Offset<-z$Off
Looking at this kind of Offset
round(as.numeric(z$Off))
The result would look like this
1 Diff<- Diff<-z$Data1-z$Data2(+22 sec)
2 Diff<- Diff<-z$Data1-z$Data2(+23 sec)
3 Diff<- Diff<-z$Data1-z$Data2(+32 sec)..........