Skip to content
Prev 69885 / 398506 Next

cumsum on chron objects

Hello Gabor,

Thanks for your reply. na.locf would replace the NA's with the most recent
non-NA, so it wouldn't create a sequence of chron dates/times (via
as.vector, as in your example). To expand my original example:
[...]
I thought one could replace the NA's by the desired interval, say 1 day,
so if the above chron object was named nachron, one could do:

nachron[is.na(nachron)] <- 1

and, for simplicity, applying on each "block" separately:

cumsum(nachron)

would give:

DateTime
13/10/03 12:30:35
14/10/03 12:30:35
15/10/03 12:30:35
16/10/03 12:30:35

for the first "block", and:

DateTime
15/10/03 16:30:05
16/10/03 16:30:05
17/10/03 16:30:05
...

for the second one. Since there are not too many blocks I may end up doing
it in Excel, but it would be nice to know how to do it in R!

Cheers and thank you,