title: Assign a column of a data.frame with string name in R
body: <p>I am trying to assign data to an existing dataframe with a name generated in a loop.  A basic example might be</p>
  
  <pre><code>A = data.frame(a = c(1,2,3), b=c(3,6,2))
  
  for (i in 1:2){
      name = paste("Name",i, sep="")
      assign(name, c(6,3,2))
  }
  </code></pre>
  
  <p>Now I just need to figure out how to add name1 and name2 to the data.frame A, while keeping their assigned name. I'm sure there is an easy answer, I'm just not seeing it right now. </p>
  
  <p>in the end I would like to end up with </p>
  
  <pre><code>A
  #a b name1 name2
  #1 3 6      6
  #2 6 3      3
  #3 2 2      2
  </code></pre>
  
  <p>But I need to do this in an automated fashion.  </p>
  
  <p>For instance if the for loop could be adapted to be like </p>
  
  <pre><code>for (i in 1:2){
      name = paste("Name",i, sep="")
      assign(name, c(6,3,2)
      A= cbind(A, get(paste(name,i,sep="")))  # works but doesn't maintain the column name as name1 or name2 etc
  }
  </code></pre>
  
  <p>this however doesn't maintain column names </p>