I have a sampling period in R:
> str(d)
'data.frame': 5 obs. of 3 variables:
$ date: POSIXct, format: "2010-03-04 20:47:00" "2010-03-04 21:47:00" ...
$ x : num 0 10 11 15.2 20
$ y : num 0 5 7.5 8.4 12.5
> d
date x y
1 2010-03-04 20:47:00 0.0 0.0
2 2010-03-04 21:47:00 10.0 5.0
3 2010-03-04 22:47:00 11.0 7.5
4 2010-03-04 23:47:00 15.2 8.4
5 2010-03-05 00:47:00 20.0 12.5
In this example, samples for x and y are taken every hour (but the time delta is not fixed). The x and y values ββare always rising (for example, a mileage counter in a car). I need a delta, how much was between them, something like this:
1 2010-03-04 20:47:00 0.0 0.0
2 2010-03-04 21:47:00 10.0 5.0
3 2010-03-04 22:47:00 1.0 2.5
4 2010-03-04 23:47:00 4.2 0.9
5 2010-03-05 00:47:00 4.8 4.1
And I also need delta for time (x and y delta divided by time - delta per hour)
How would this be done in R?
source
share