title: for loop with "<-" to create variables in R
body: <p>So I have this data :</p>
  <pre><code>data&lt;-as.data.frame(matrix(1:9,ncol=3))
  </code></pre>
  <p>which gives this :</p>
  <pre><code>| V1 | V2 | V3 |  
  ________________  
  |  1 | 2  | 3  | 
  |  4 | 5  | 6  |
  |  7 | 8  | 9  |
  </code></pre>
  <p>I want to create a variable for each column to get this :</p>
  <pre><code>&gt; V1
  [1] 1 2 3
  
  &gt; V2
  [1] 4 5 6
  
  &gt; V3
  [1] 7 8 9
  </code></pre>
  <p>I know that if I do a loop with the assign function :</p>
  <pre><code>for (i in 1:length(data)) {
                 assign(names(data[i]),data[,i])
                 
  }
  </code></pre>
  <p>it works. But if I try with the &quot;&lt;-&quot; :</p>
  <pre><code>for (i in 1:length(data)) {
             names(data[i])&lt;-data[,i]
             
  }
  </code></pre>
  <p>it does not work.
  Why does it work with the assign function but not with the &quot;&lt;-&quot; ?</p>