title: conditional sequence across rows in a new column
body: <p>If there's a "6" in <code>df$a</code>, I'd like <code>1:9</code> from the previous September to next May, to be in a new column, shown here as <code>df$b</code>, with <code>NA</code> as the rest.</p>
  
  <pre><code>library(tidyverse)
  library(lubridate)
  date &lt;- c("2/29/1940","3/31/1940","4/30/1940","5/31/1940","6/30/1940","7/31/1940","8/31/1940","9/30/1940","10/31/1940","11/30/1940","12/31/1940","1/31/1941","2/28/1941",
         "3/31/1941","4/30/1941","5/31/1941","6/30/1941","7/31/1941","8/31/1941","9/30/1941","10/31/1941","11/30/1941", "12/31/1941","1/31/1942","2/28/1942","3/31/1942",
         "4/30/1942","5/31/1942", "6/30/1942","7/31/1942","8/31/1942","9/30/1942","10/31/1942","11/30/1942","12/31/1942","1/31/1943","2/28/1943","3/31/1943","4/30/1943",
         "5/31/1943","6/30/1943","7/31/1943", "8/31/1943","9/30/1943")
  a &lt;- c("NA","NA","NA","NA","NA","NA","NA","NA","NA","NA","NA","NA",6,"NA","NA","NA","NA","NA","NA","NA","NA","NA","NA","NA","NA","NA","NA","NA","NA","NA","NA","NA","NA",
     "NA","NA","NA","NA","NA","NA","NA","NA","NA","NA","NA")
  df &lt;- data.frame(date, a)
  df %&lt;&gt;% mutate(date = mdy(date), a)
  
  df:
  date        a   b
  2/29/1940   NA  NA
  3/31/1940   NA  NA
  4/30/1940   NA  NA
  5/31/1940   NA  NA
  6/30/1940   NA  NA
  7/31/1940   NA  NA
  8/31/1940   NA  NA
  9/30/1940   NA  1
  10/31/1940  NA  2
  11/30/1940  NA  3
  12/31/1940  NA  4
  1/31/1941   NA  5
  2/28/1941   6   6
  3/31/1941   NA  7
  4/30/1941   NA  8
  5/31/1941   NA  9
  6/30/1941   NA  NA
  7/31/1941   NA  NA
  8/31/1941   NA  NA
  9/30/1941   NA  NA
  10/31/1941  NA  NA
  11/30/1941  NA  NA
  12/31/1941  NA  NA
  1/31/1942   NA  NA
  2/28/1942   NA  NA
  3/31/1942   NA  NA
  4/30/1942   NA  NA
  5/31/1942   NA  NA
  6/30/1942   NA  NA
  7/31/1942   NA  NA
  8/31/1942   NA  NA
  9/30/1942   NA  NA
  10/31/1942  NA  NA
  11/30/1942  NA  NA
  12/31/1942  NA  NA
  1/31/1943   NA  NA
  2/28/1943   NA  NA
  3/31/1943   NA  NA
  4/30/1943   NA  NA
  5/31/1943   NA  NA
  6/30/1943   NA  NA
  7/31/1943   NA  NA
  8/31/1943   NA  NA
  9/30/1943   NA  NA
  </code></pre>
  
  <p>For more context, I have a hundred years or so of monthly data in a data frame and I'm looking for an efficient way to produce the third column given the first two columns, to process/visualize other data not shown.  Only sometimes there is a 6 for February in <code>df$a</code>. When so, I'd like the previous September through the next May to be populated as shown in a new column (I'm looking to produce <code>df$b</code>). I tried some clumsy ways, mostly by a bunch of lines with variations of  <code>mutate()</code> , <code>lag()</code> , and <code>lead()</code> but have a good feeling there's more direct routes.</p>
  
  <p>thank you,</p>
  
  <p>dave</p>