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

Counting and matching over a time interval [closed]

$
0
0

For a +/- 2 month-year interval, I wish to calculate for a given "id", how many times did that "id" appear in the "id2" column. I am wondering if there is an efficient solution in R.

myData <- structure(list(id = c(4217, 3217, 4217, 3217, 4217, 3217, 4217,3217, 3217, 4217), monthyear = c("2003m10", "2003m11", "2003m11","2004m1", "2004m1", "2004m2", "2004m2", "2004m10", "2004m10","2017m2"), id2 = c(NA, 4217, NA, 4217, NA, NA, 4217, 4217, 4217,NA)), row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"))

What I am looking for is, for a fixed id, how many times the specific id==id2 in that time interval. For example, for id 4217 in monthyear 2004m8, id2==4217 11 times in the +/- 2 month interval.

Any help would be much appreciated.


Viewing all articles
Browse latest Browse all 206278

Trending Articles



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