title: How to roll max forward for my entire table set?
body: <p>So I have a dataset called aaa that looks like this:</p>
  <pre><code>Date      100.sh 101.sh 102.sh 100.sz 101.sz 102.sz ... xxx.xx 
  2009 Q1      1      1      0      0     0      NA          ...
  2009 Q2      0      0      1      0     0      NA          ...
  2009 Q3      0      0      1      NA    0      NA          ...
  2009 Q4      0      0      0      1     0      NA          ...
  2010 Q1      1      0      1      0     0      NA          ...
  2010 Q2.     0      0      0      0     0       1          ...
  ...
  2020 Q3      0      0      0      1     0       0          ...
  </code></pre>
  <p>My goal is to change this table and see if in the next four quarters there's any 1s or 0s or NAs from the current quarter. So basically I'm trying to find the roll-max for the next four quarters (not including current quarter), so if for example if 100.sh at 2009 Q1 in the next four quarters (2009 Q2-2010 Q2) has any 1 then it would be 1, if for the next for four quarters it only has 0 then it would be zero, if for the next four quarters it's all NA then NA.That's why I used rollmax since the max would be 1 anyways.</p>
  <p>Here are some ways that I tried:</p>
  <pre><code>aaaa&lt;-rollmax(aaa[-1], 4, align=&quot;left&quot;, na.rm-TRUE, partial=TRUE, fill=0)
  </code></pre>
  <p>But it gives me the error :not compatible with requested type: [type=list:target=double]</p>
  <p>So I tried:</p>
  <pre><code>aaaa&lt;-rollmax(aaa[-1], 4, align=&quot;left&quot;, na.rm=TRUE, partial=TRUE, fill=0)
  </code></pre>
  <p>But it gives me the error in match.arg(align): 'arg' should be one of &quot;right&quot;</p>
  <pre><code>aaaa&lt;-rollapplyr(aaa[-1],4,max, align=&quot;left&quot;, na.rm=TRUE, partial=TRUE, fill=0)
  </code></pre>
  <p>However, this just removes the date and gives me a string of num.</p>
  <p>I also tried:</p>
  <pre><code>aaaa&lt;-rollmaxr(aaa, 4,align=&quot;left&quot;, na.rm=TRUE, partial=TRUE, fill=0)
  </code></pre>
  <p>This also gives me a string of num with the dates.</p>
  <p>Then I tried:</p>
  <pre><code>  aaa[roll_max(aaa,4)]
  </code></pre>
  <p>But this also gives me error :not compatible with requested type: [type=list:target=double]</p>
  <p>I would like to keep the dates the same and not roll on the dates while keeping it as a data.frame so the results look like this:</p>
  <pre><code>Date      100.sh 101.sh 102.sh 100.sz 101.sz 102.sz ... xxx.xx 
  2009 Q1      1      0      1      1     0      NA          ...
  2009 Q2      1      0      1      1     0       1          ...
  2009 Q3      1      0      1      1     0       1          ...
  2009 Q4      1      0      1      0     0       1          ...
  2010 Q1      0      0      1      0     0       1          ...
  2010 Q2             depends on next four quarter           ...
  ...  
  2020 Q3      0      0      0      0     0       0          ...
  </code></pre>
  <p>(in the table above some of the 0s and 1 from 2009 Q2 and beyond do depend on the list in the next four quarters if there are 1s I just assumed but it's a rough idea of whåt  I want the table to look like, sorry!)</p>
  <p>Is there any way to keep the dates the same and find the forward rolling max for the future four quarters if there's any 1 then 1, maybe <code>case_when ~1 ~0 ~NA</code> or using <code>if</code> &amp; <code>any</code> would be a better way to do it?</p>
  <p>Thanks for all your help!</p>