title: String to variable name in R
body: <p>I am cleaning a data set and I need to choose the variables depending on another variable. Let's say that if <code>ID = 1</code>, I need to introduce in the data frame the variable <code>VAR01</code>, if <code>ID = 2</code>, I need <code>VAR02</code>, and so on. </p>
  
  <p>Thus, I'm doing a for loop where I paste the variable name 'VAR' with the ID number with the <code>stringf</code> function. The problem is that I need R to understand the string as a function name.</p>
  
  <p>I've found in the forum this solution, which doesn't work for me:</p>
  
  <pre><code>&gt; variable1 = c("monday", "tuesday", "wednesday")
  
  &gt; var_name = "variable1"
  
  &gt; eval(parse(text=var_name))
  [1] "monday"    "tuesday"   "wednesday"
  </code></pre>
  
  <p>The problem is I cannot use it to refer to the variable:</p>
  
  <pre><code>&gt; eval(parse(text=var_name)) = c(1,2,3)
  Error in file(filename, "r") : cannot open the connection
  In addition: Warning message:
  In file(filename, "r") :
  cannot open file 'variable1': No such file or directory
  </code></pre>
  
  <p>Has anyone got a solution?</p>
  
  <p>Thanks!</p>