I need to sum the number of times, starting from the last value, that the r element appears in my vector until it reaches an a element. For example, suppose I have a vector V = c('a', 0, 'a', 'r', 'r', 0, 'r', 'a', 0, 'a', 'r' , 0, 'r').
Note that in this case, the number of times that the element r appears until appears an a is 2 times. So I would need a to return the number 2 to me, in addition to bringing up the positions at which they appear, ie, position 13 and 11. Something like
> some.function(c('a', 0, 'a', 'r', 'r', 0, 'r', 'a', 0, 'a', 'r' , 0, 'r'))
[1] 2
[2] 13
[3] 11
> some.function(c('a', 0, 'a', 'r', 'r', 0, 'r', 'a', 0, 'a', 'r'))
[1] 1
[2] 11
> some.function(c('a', 0, 'a', 'r', 'r', 0, 'r'))
[1] 3
[2] 7
[3] 5
[4] 4
> some.function(c('a', 0, 'a', 'r', 'r', 0, 'r', 0))
[1] 3
[2] 7
[3] 5
[4] 4
Any hint on how can I do that?