title: To replace a string within a for loop in R
body: <p>I have many text files</p>
  
  <pre><code>fr.txt
  no.txt
  sta.txt
  sto.txt
  </code></pre>
  
  <p>I create a vector with filename as string </p>
  
  <pre><code>string &lt;- c("fr","no","sta","sto")
  </code></pre>
  
  <p>And I would like to use for loop in R to use string as the variable names and to read the corresponding files.   </p>
  
  <pre><code>for (type in c("fr","no","sta","sto")){type &lt;- read.table(sprintf("%s.txt", type),header=TRUE)}
  </code></pre>
  
  <p>For example</p>
  
  <pre><code>fr &lt;- read.table("fr.txt",header=TRUE)
  no &lt;- read.table("no.txt",header=TRUE)
  sta &lt;- read.table("sta.txt",header=TRUE)
  </code></pre>
  
  <p>How should I start with ? The above for loop failed to do what I want.</p>