title: Can I combine a dplyr mutate_at & mutate_if statement?
body: <p>I have the following example output:</p>
  
  <pre><code>   country country-year year     a     b
  1  France  France2000   2000       NA    NA 
  2  France  France2001   2001     1000  1000  
  3  France  France2002   2002       NA    NA
  4  France  France2003   2003     1600  2200
  5  France  France2004   2004       NA    NA
  6  UK          UK2000   2000     1000  1000  
  7  UK          UK2001   2001       NA    NA
  8  UK          UK2002   2002     1000  1000  
  9  UK          UK2003   2003       NA    NA
  10 UK          UK2004   2004       NA    NA
  11 Germany     UK2000   2000       NA    NA 
  12 Germany     UK2001   2001       NA    NA
  13 Germany     UK2002   2002       NA    NA  
  14 Germany     UK2003   2003       NA    NA
  15 Germany     UK2004   2004       NA    NA
  </code></pre>
  
  <p>I want to interpolate the data I (but not extrapolate), and remove the columns for which columns <code>a</code> and <code>b</code> are both NA. In other words I would like to remove all the columns for which I cannot interpolate; in the example:</p>
  
  <pre><code>1  France  France2000        NA    NA
  5  France  France2004        NA    NA
  9  UK          UK2003        NA    NA
  10 UK          UK2004        NA    NA
  11 Germany     UK2000        NA    NA 
  12 Germany     UK2001        NA    NA
  13 Germany     UK2002        NA    NA  
  14 Germany     UK2003        NA    NA
  15 Germany     UK2004        NA    NA
  </code></pre>
  
  <p>There are two options that almost do what I want:</p>
  
  <pre><code>library(tidyverse)
  library(zoo)
  df %&gt;%
    group_by(country) %&gt;%
    mutate_at(vars(a:b),~na.fill(.x,c(NA, "extend", NA))) %&gt;% 
    filter(!is.na(a) | !is.na(b))
  </code></pre>
  
  <p>AND</p>
  
  <pre><code>df%&gt;% 
    group_by(Country)%&gt;% 
    mutate_if(is.numeric,~if(all(is.na(.x))) NA else na.fill(.x,"extend"))
  </code></pre>
  
  <p>Would it be possible to combine these codes, doing something like this:</p>
  
  <pre><code>df &lt;- df%&gt;%
    group_by(country)%&gt;%
    mutate_at(vars(a:b),~if(all(is.na(.x))) NA else(.x,c(NA, "extend", NA)))
    filter(!is.na(df$a | df$a))
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>   country country-year    a     b 
  2  France  France2001      1000  1000  
  3  France  France2002      1300  1600
  4  France  France2003      1600  2200
  6  UK          UK2000      1000  1000  
  7  UK          UK2001         0     0
  8  UK          UK2002      1000  1000
  </code></pre>