title: Creating a vector with specific values out of a colSums(DF)
body: <p>I have the following DF:</p>
  
  <pre><code>&gt; str(fngr_rain)
  'data.frame':   80 obs. of  9 variables:
   $ CRP: int  0 0 0 0 0 0 0 0 0 0 ...
   $ CRO: int  0 0 0 0 0 0 0 0 0 0 ...
   $ EPR: int  1 1 0 0 1 1 1 1 1 0 ...
   $ EPO: int  1 1 1 1 1 1 1 1 1 1 ...
   $ ARB: int  0 0 0 0 0 0 0 0 0 0 ...
   $ OPP: int  1 0 1 1 1 1 1 1 0 1 ...
   $ AAT: int  0 0 0 0 0 0 0 0 0 0 ...
   $ LCA: int  1 0 0 0 0 0 0 0 0 0 ...
   $ ATN: int  0 0 0 0 0 0 0 0 0 0 ...
  </code></pre>
  
  <p>I want to create a function which makes a vector of the colSums of this DF. The catch is: I need the vector to have only the values of colSums which are greater than 4. So, instead of this:</p>
  
  <pre><code>&gt; colSums(fngr_rain)
  CRP CRO EPR EPO ARB OPP AAT LCA ATN 
    3   0  48  80   3  51   1  25   0
  </code></pre>
  
  <p>I want the following vector:</p>
  
  <pre><code>&gt; vector1 &lt;- c("EPR" = 48, "EPO" = 80, "OPP" = 51, "LCA" = 25)
  &gt; vector1
  EPR EPO OPP LCA 
   48  80  51  25 
  </code></pre>
  
  <p>I was trying something like this:</p>
  
  <pre><code>&gt; my_fun = function(x) {
  +     sapply(as.vector(colSums(x)), function(x){
  +         if(x &gt;= 4) assign("my_vec", x, envir = .GlobalEnv)
  +         }
  +     )
  + }
  &gt; my_fun(fngr_rain)
  [[1]]
  [1] 3
  
  [[2]]
  [1] 0
  
  [[3]]
  NULL
  
  [[4]]
  NULL
  
  [[5]]
  [1] 3
  
  [[6]]
  NULL
  
  [[7]]
  [1] 1
  
  [[8]]
  NULL
  
  [[9]]
  [1] 0
  </code></pre>
  
  <p>EDIT:
  It returns me a list with the vector. I can then get the vector using unlist() (as shown in the comments)</p>
  
  <pre><code>unlist(my_fun(fngr_rain))
  [1] 3 0 3 1 0
  </code></pre>
  
  <p>However, I still wanted the vector to be stored in an object. I tried to do that in my function, but the "my_vec" object I created does not return me the vector:</p>
  
  <pre><code>&gt; my_vec
  [1] 0
  </code></pre>
  
  <p>Any help appreciated!</p>