title: R: loop through list
body: <p>I've come over this problem a few times by now, and this time I am eager to get an efficient solution. The underlying problem is that I want to loop through a list of variables with the <code>paste</code> function. </p>
  
  <pre><code>dat &lt;- read.csv("some file", header=TRUE)  
  
  list.R &lt;- c("IC","IG","DM","IM","IN","EN","RM")  
  
  for (RO in list.R){
              paste("dat$",RO,"_I", sep="")[
              paste("dat$",RO,"_I", sep="") == 
              "Strongly disagree"] &lt;- 1
              }
  </code></pre>
  
  <p>I pasted the name of the variable together, but this gives me a string in block quotes. I've tried the following but nothing worked so far:</p>
  
  <pre><code>eval(parse(text=paste("dat$",RO,"_I", sep="")))
  </code></pre>
  
  <p>or </p>
  
  <pre><code>get(paste("dat$",RO,"_I", sep=""))
  </code></pre>
  
  <p>do you know how to solve this so that the loop works?
  I would very much appreciate your help :)</p>
  
  <p>(I know in this case I could also use <code>as.numeric(levels(dat$IC_I))[dat$IC_I]</code>
  but the order of the levels is wrong)</p>