【发布时间】:2021-07-31 04:06:25
【问题描述】:
我之前问过以下问题:In R: subset so that I only have the observations 3 years prior to and after an event
我该如何做同样的事情,但限制是在日期之前或之后至少 3 年,而不是必须准确地在之前和之后 3 年?
如果我有这样的数据:
companyID year status
1 2000 1
1 2001 1
1 2002 1
1 2003 1
1 2004 0
1 2005 2
1 2006 2
1 2007 2
2 2012 1
2 2013 0
2 2014 2
2 2015 2
2 2016 2
3 2008 1
3 2009 1
3 2010 1
3 2011 1
3 2012 1
3 2013 0
3 2014 2
3 2015 2
3 2016 2
3 2017 2
因此,我希望我的数据看起来像这样:
companyID year status
1 2000 1
1 2001 1
1 2002 1
1 2003 1
1 2004 0
1 2005 2
1 2006 2
1 2007 2
3 2008 1
3 2009 1
3 2010 1
3 2011 1
3 2012 1
3 2013 0
3 2014 2
3 2015 2
3 2016 2
3 2017 2
提前感谢您的指导!!
【问题讨论】: