Question

R newbie so apologies if this is easy..

I've got an irregular zoo containing some sensor readings anywhere between 15 seconds and 5 minutes apart- if the gap is much longer than 5 minutes something is wrong.

> z[1:5,]
                    Amb HWS
2012-06-01 00:00:14 184 182
2012-06-01 00:00:29 184 182
2012-06-01 00:00:44 183 182
2012-06-01 00:00:59 183 182
2012-06-01 00:01:14 183 182

I can find the start of a gap longer than 300 seconds with

>gap_ts=index(z[diff(index(z))>300])
> gap_ts[1:5]
[1] "2012-06-02 00:31:31 GMT" "2012-06-06 11:46:31 GMT" "2012-06-06 21:55:31 GMT"
[4] "2012-06-08 07:05:32 GMT" "2012-06-11 07:01:19 GMT"

However I cant figure out how to get the corresponding end time of each such gap.

I'd like to be able to produce a list with the start and end times of each gap.

Can anyone advise how this can be done? Maybe an alternative approach?

Was it helpful?

Solution

Try:

gap_ts=index(z[ which( diff(index(z))>300 ) +1 ])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top