First, merge your xx
object with an empty xts object containing your breakpoints.
xs <- merge(xx, xts(,as.POSIXct(spltr)))
Then you can find the 'endpoints' of your spltr
object in xs
by using the which.i
argument to [.xts
.
ep <- c(0,xs[as.POSIXct(spltr),which.i=TRUE])
Now you can use period.apply
on the xs
object (making sure to deal with any potential NA
).
> period.apply(xs, ep, function(x) nrow(na.omit(x)))
xx
2014-01-13 12:09:32 0
2014-02-09 06:23:41 0
2014-03-01 13:35:12 13
2014-05-14 07:12:52 13