Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a time offset for a zoo object
    primarykey
    data
    text
    <p>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. </p> <pre><code>Date&lt;- as.POSIXct("2012-01-01 08:00:00") + 1:120 V1&lt;-rnorm(200,mean=5) #Velocity in m/sec R&lt;-rnorm(4,mean=3) V2&lt;-V1+R #Velocity in m/sec Data1&lt;-rnorm(200, mean=20) Data2&lt;-rnorm(200, mean=25) V&lt;-data.frame(V1,V2,Data1,Data2) z&lt;-zoo(as.matrix(V),order.by=Date) L&lt;-170 #Length =170m </code></pre> <p>If I average the velocity data</p> <pre><code>z$Avg_Vel&lt;-rowMeans(z[,1:2]) </code></pre> <p>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.</p> <pre><code>z$Off&lt;-L/z$Avg_Vel </code></pre> <p>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</p> <pre><code>Diff&lt;-z$Data1-z$Data2 </code></pre> <p>As this does not include the offset</p> <p>If it takes 2 minutes for the particles to travel from point 1 to point 2, than I would want</p> <pre><code>Diff&lt;-z$Data1-z$Data2(+2min) </code></pre> <p>So that I am looking at the difference between Data1 at time x, and Data2 at time x+2min</p> <p>To clarify in response to an answer, the end result would be a rolling offset. So that </p> <pre><code> Offset&lt;-z$Off </code></pre> <p>Looking at this kind of Offset</p> <pre><code>round(as.numeric(z$Off)) </code></pre> <p>The result would look like this</p> <pre><code>1 Diff&lt;- Diff&lt;-z$Data1-z$Data2(+22 sec) 2 Diff&lt;- Diff&lt;-z$Data1-z$Data2(+23 sec) 3 Diff&lt;- Diff&lt;-z$Data1-z$Data2(+32 sec).......... </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload