title: Why for loop only shows result of last loop
body: <p>I have this sample matrix:</p>
  
  <pre><code>  X1 X2 X3 X4
  1  F  F  F  F
  2  C  C  C  C
  3  D  D  D  D
  4 A# A# A#  A
  </code></pre>
  
  <p>And I'm trying to use a for loop to get the number of unique pitches in each column. Here's how I'm trying to do it: </p>
  
  <pre><code>y &lt;- read.csv(file)
  frame &lt;- data.frame(y)
  for(i in 1:4){
  specframe &lt;- frame[, i]
  x &lt;- unique(specframe)
           }
       length(x)
  </code></pre>
  
  <p>But the result of length is just 4. The output I'm looking for is a vector of 4 elements in which each element details the number of unique elements in their respective columns. It looks like the for loop is rewriting x every time it loops, so how would I make a vector which contains an element for each time it loops?</p>