I have an xts object which consists of just 1s and 0s, but mainly zeros, and I was wondering if there was a smart/efficient method of working out the number of rows (not days) between two 1s
and example of part of what the object looks like...
x1
2012-12-13 0
2012-12-14 0
2012-12-17 0
2012-12-18 1
2012-12-19 0
2012-12-20 0
2012-12-21 0
2012-12-24 0
2012-12-26 0
2012-12-27 0
2012-12-28 0
2012-12-31 0
2013-01-02 0
2013-01-03 0
2013-01-04 0
2013-01-07 0
2013-01-08 0
2013-01-09 0
2013-01-10 0
2013-01-11 0
2013-01-14 0
2013-01-15 1
2013-01-16 0
2013-01-17 0
2013-01-18 0
2013-01-22 0
2013-01-23 0
2013-01-24 0
2013-01-25 0
2013-01-28 0
2013-01-29 0
basically I would like to have a vector/xts object next to the 1s and 0s on the 19th Dec 2012 till 15th Jan 2013 that has the number 18 as there are 18 rows between the two 1s in th example....there are more 1s and 0s the further back in time you go...but would basically like to see that for each day the value of the vector/xts column would be the number of rows there are till the next 1....i hope that makes sense? so something like this..
x1 x2
2012-12-13 0 19
2012-12-14 0 19
2012-12-17 0 19
2012-12-18 1 19
2012-12-19 0 18
2012-12-20 0 18
2012-12-21 0 18
2012-12-24 0 18
2012-12-26 0 18
2012-12-27 0 18
2012-12-28 0 18
2012-12-31 0 18
2013-01-02 0 18
2013-01-03 0 18
2013-01-04 0 18
2013-01-07 0 18
2013-01-08 0 18
2013-01-09 0 18
2013-01-10 0 18
2013-01-11 0 18
2013-01-14 0 18
2013-01-15 1 18
2013-01-16 0 20
2013-01-17 0 20
2013-01-18 0 20
2013-01-22 0 20
2013-01-23 0 20
2013-01-24 0 20
2013-01-25 0 20
2013-01-28 0 20
2013-01-29 0 20
etc...