A more general version of this question has been answered here. A user proposed I ask this more specific version of the question as a separate post.
I have two logical vectors which look like this:
x = c(0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0)
y = c(0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0)
I want to count the intersections between ranges of consecutive values (in this example 1111) in such a way, that at most one intersection per run of 1s in the first vector is counted.
Using sum(rle(x & y)$values)
from the above mentioned answer, I can count the total number of intersections of the above vectors as two, but I expect one.