如何通过使用lag()或lead()函数在小标题列中找到最长的连续条纹

时间:2019-11-21 17:08:27

标签: r lag tibble lead

我有以下提示:

results_summary_tbl <- tribble(
  ~event_id, ~most_wins_in_a_row, ~number_of_winners, ~winners,                              ~years,
   "A",       3,                  1,                   "4322",                               "4322 = (2011, 2013, 2014)",
   "C",       2,                  2,                   "5556 , 2391",                        "5556 = (2011, 2013), 2391 = (2015, 2016)",
   "B",       2,                  1,                   "7893",                               "7893 = (2013, 2014)",
   "D",       1,                  5,                   "4219 , 7623 , 8003 , 2851 , 0418",   "4219 = (2011), 7623 = (2013), 8003 = (2014), 2851 = (2016), 0418 = (2017)"
)

对于每个事件,我想使用lag()和/或lead()函数找到最长的条纹。预期的输出应如下所示:

{{1}}

谢谢

0 个答案:

没有答案