title: Get column names with zero variance using dplyr
body: <p>I'm trying to find any variables in my data that have zero variance (i.e. constant continuous variables).  I figured out how to do it with lapply but I would like to use dplyr as I'm trying to follow tidy data principles.  I can create a vector of just the variances using dplyr but its the last step where I find the values not equal to zero and return the variable names that confusing me.</p>
  
  <p>Here's the code
  
  <br/></p>
  
  <pre class="lang-r prettyprint-override"><code>library(PReMiuM)
  library(tidyverse)
  #&gt; ── Attaching packages ───────────────────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
  #&gt; ✔ ggplot2 2.2.1     ✔ purrr   0.2.4
  #&gt; ✔ tibble  1.4.2     ✔ dplyr   0.7.4
  #&gt; ✔ tidyr   0.7.2     ✔ stringr 1.2.0
  #&gt; ✔ readr   1.2.0     ✔ forcats 0.2.0
  #&gt; ── Conflicts ──────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
  #&gt; ✖ dplyr::filter() masks stats::filter()
  #&gt; ✖ dplyr::lag()    masks stats::lag()
  
  
  setwd("~/Stapleton_Lab/Projects/Premium/hybridAnalysis/")
  
  # read in data from analysis script
  df &lt;- read_csv("./hybrid.csv")
  #&gt; Parsed with column specification:
  #&gt; cols(
  #&gt;   .default = col_double(),
  #&gt;   Exp = col_character(),
  #&gt;   Pedi = col_character(),
  #&gt;   Harvest = col_character()
  #&gt; )
  #&gt; See spec(...) for full column specifications.
  
  # checking for missing variable
  # df %&gt;% 
  #     select_if(function(x) any(is.na(x))) %&gt;% 
      # summarise_all(funs(sum(is.na(.))))
  
  
  # grab month for analysis
  may &lt;- df %&gt;% 
      filter(Month==5)
  june &lt;- df %&gt;% 
      filter(Month==6)
  july &lt;- df %&gt;% 
      filter(Month==7)
  aug &lt;- df %&gt;% 
      filter(Month==8)
  sept &lt;- df %&gt;% 
      filter(Month==9)
  oct &lt;- df %&gt;% 
      filter(Month==10)
  
  # check for zero variance in continuous covariates
  numericVars &lt;- grep("Min|Max",names(june))
  
  zero &lt;- which(lapply(june[numericVars],var)==0,useNames = TRUE)
  
  noVar &lt;- june %&gt;% 
  
      select(numericVars) %&gt;% 
  
      summarise_all(var) %&gt;% 
  
      filter_if(all, all_vars(. != 0))
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  
  #&gt; Warning in .p(.tbl[[vars[[i]]]], ...): coercing argument of type 'double'
  #&gt; to logical
  </code></pre>