title: Find columns that have identical values
body: <p>Problem statement:
  I actually want to eliminate from further analysis columns that have identical values in all cells. In order to do this, I want to find the columns that have identical values.</p>
  <p>I wrote the following code which seems to be working for the dataframe test but not for the real dataframe stpo</p>
  <pre><code>
      library(&quot;dplyr&quot;)
      library(&quot;purrr&quot;)
      test_unique &lt;- function(x)
      {
        return(length(unique(x)))
      }
      
      test &lt;-data.frame(c1 = c(&quot;a&quot;, &quot;a&quot;), c2 = c(NA, NA), c3 =  c(1,2), c4=c(NA, 4))
      # What I want to find out the columns that have the same value throughout
      res &lt;- map(test[,c(names(test))], test_unique)
      res
      # But when I try to apply the same thing to the dataset below, it does not work. 
      # Not sure what the reason is. Is there a better way to do this? Perhaps using data.table? What am I doing wrong?
      res2 &lt;- map(stpo[,c(names(stpo))], test_unique)
      res2
  
     
      I am not exactly sure how to put the result of dput. I am putting this below (this is the dataframe stpo)
  
  </code></pre>
  <pre><code>structure(list(stlnr = c(1L, 2L, 3L, 3L, 3L, 3L, 4L), stlkn = c(1L, 
  1L, 1L, 2L, 3L, 4L, 5L), stpoz = c(2L, 2L, 2L, 4L, 6L, 8L, 10L
  ), aennr = c(NA, NA, NA, NA, NA, NA, NA), vgknt = c(0L, 0L, 0L, 
  0L, 0L, 0L, 0L), idnrk = c(&quot;test_1&quot;, &quot;test_1&quot;, &quot;test_2&quot;, &quot;test_3&quot;, 
  &quot;test_3&quot;, &quot;test_1&quot;, &quot;test_2&quot;), pswrk = c(NA, NA, NA, NA, NA, 
  NA, NA), meins = c(&quot;EA&quot;, &quot;EA&quot;, &quot;EA&quot;, &quot;EA&quot;, &quot;EA&quot;, &quot;EA&quot;, &quot;EA&quot;), 
      menge = c(1, 14, 4, 4, 2, 2, 1), fmeng = c(NA, NA, NA, NA, 
      NA, NA, NA), ausch = c(0, 0, 0, 0, 0, 0, 0), avoau = c(0, 
      0, 0, 0, 0, 0, 0), netau = c(NA, NA, NA, NA, NA, NA, NA), 
      erskz = c(NA, NA, NA, NA, NA, NA, NA), rekri = c(NA, NA, 
      NA, NA, NA, NA, NA), rekrs = c(NA, NA, NA, NA, NA, NA, NA
      ), nlfzt = c(0L, 0L, 0L, 0L, 0L, 0L, 0L), verti = c(NA, NA, 
      NA, NA, NA, NA, NA), alpos = c(NA, NA, NA, NA, NA, NA, NA
      ), ewahr = c(0L, 0L, 0L, 0L, 0L, 0L, 0L), ekgrp = c(NA, NA, 
      NA, NA, NA, NA, NA), lifzt = c(0L, 0L, 0L, 0L, 0L, 0L, 0L
      ), lifnr = c(NA, NA, NA, NA, NA, NA, NA), roms1 = c(0, 0, 
      0, 0, 0, 0, 0), roms2 = c(0, 0, 0, 0, 0, 0, 0), roms3 = c(0, 
      0, 0, 0, 0, 0, 0), romen = c(0, 0, 0, 0, 0, 0, 0), rform = c(NA, 
      NA, NA, NA, NA, NA, NA), upskz = c(NA, NA, NA, NA, NA, NA, 
      NA), valkz = c(NA, NA, NA, NA, NA, NA, NA), matkl = c(NA, 
      NA, NA, NA, NA, NA, NA), webaz = c(0L, 0L, 0L, 0L, 0L, 0L, 
      0L), clobk = c(NA, NA, NA, NA, NA, NA, NA), lgort = c(NA, 
      NA, NA, NA, NA, NA, 14L), kzkup = c(NA, NA, NA, NA, NA, NA, 
      NA), dvnam = c(NA, NA, NA, NA, NA, NA, NA), dspst = c(NA, 
      NA, NA, NA, NA, NA, NA), alpst = c(NA, NA, NA, NA, NA, NA, 
      NA), alprf = c(0L, 0L, 0L, 0L, 0L, 0L, 0L), alpgr = c(NA, 
      NA, NA, NA, NA, NA, NA), kstty = c(NA, NA, NA, NA, NA, NA, 
      NA), kstnr = c(NA, NA, NA, NA, NA, NA, NA), nlfzv = c(0L, 
      0L, 0L, 0L, 0L, 0L, 0L), nlfmv = c(NA, NA, NA, NA, NA, NA, 
      NA), idhis = c(0L, 0L, 0L, 0L, 0L, 0L, 0L), idvar = c(NA, 
      NA, NA, NA, NA, NA, NA), itsob = c(NA, NA, NA, NA, NA, NA, 
      NA), cufactor = c(0L, 0L, 0L, 0L, 0L, 0L, 0L), funcid = c(NA, 
      NA, NA, NA, NA, NA, NA)), row.names = c(NA, -7L), class = c(&quot;data.table&quot;, 
  &quot;data.frame&quot;), .internal.selfref = &lt;pointer: 0x0000022534c51ef0&gt;)
  </code></pre>
  <pre><code></code></pre>