title: save an output into a vector in R?
body: <p>I have the following function which finds the distinct number of cases belonging to 4 different factors. <code>test</code> is a list containing 4 <code>dataframes</code></p>
  
  <pre><code>for (i in test){
    i&lt;-i%&gt;%distinct(FileNumber)%&gt;%nrow()
    print(i)
  }
  </code></pre>
  
  <p>when i run this, I get the following output </p>
  
  <pre><code>[1] 38
  [1] 129
  [1] 1868
  [1] 277
  </code></pre>
  
  <p>However I want this output to be saved into another vector called my_vector. So that <code>my_vector</code> is </p>
  
  <pre><code>38 129 1868 277
  </code></pre>
  
  <p>So I tried the following based on this answer I found 
  <a href="https://stackoverflow.com/questions/26330849/saving-results-from-for-loop-as-a-vector-in-r">Saving results from for loop as a vector in r</a></p>
  
  <pre><code>library(dplyr)
  
  my_vector&lt;-vector("numeric",4L)
  
  for (i in test){
    my_vector[i]&lt;-i%&gt;%distinct(FileNumber)%&gt;%nrow()
  }
  </code></pre>
  
  <p>However when I run this I get the following message </p>
  
  <pre><code>Error in my_vector[i] &lt;- i %&gt;% distinct(FileNumber) %&gt;% nrow() : 
    invalid subscript type 'list'
  </code></pre>
  
  <p>How do I get the earlier output I listed saved into a vector?</p>