Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Counting intersections per run of 1s in the first of two logical vectors

$
0
0

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.


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>