title: R import multiple files and perform complex function on them
body: <p>I have a series of files that when I read them and manipulate them individually I don't have have problem.</p>
  <p>They are organised as follows:</p>
  <h1>e.g.</h1>
  <pre><code>chrY&lt;-read.table('chrY.txt', sep ='', header=F)
  head(chrY)
          V1
  1 4.514563
  2 4.543689
  3 4.553398
  4 4.533981
  5 4.495146
  6 4.514563
  </code></pre>
  <p>I need to convert each of the values to numeric:</p>
  <p>And so I try this for a list of chromosome files:</p>
  <pre><code>temp = list.files(pattern=&quot;chr*.txt&quot;)
  for (i in 1:length(temp)) assign(temp[i], read.table(temp[i], sep ='', header=F))
  &gt; temp
  [1] &quot;chr17.txt&quot; &quot;chr18.txt&quot;
  [3] &quot;chr19.txt&quot; &quot;chr1.txt&quot; 
  [5] &quot;chr6.txt&quot;  &quot;chrY.txt&quot;     
      
  </code></pre>
  <p>Conversion to numerics:</p>
  <pre><code>for(i in temp){
    temp[i]&lt;-as.numeric(temp[i])
  }
  </code></pre>
  <p>I wanted to plot over the average of all the files and plot over them,</p>
  <p>Plotting one imported file is fine:</p>
  <pre><code>plot(chrY.txt[,1])
  </code></pre>
  <p>my attempt at plotting the average values between all of them as follows:</p>
  <pre><code>for(i in length(temp)-1){ #index -1 such that iteration is not out of range
   x&lt;-(temp[i][,1]+temp[i+1][,1])/length(temp)
  }
  plot(x)
  </code></pre>
  <p>however for the averaging-process I get the following error:</p>
  <blockquote>
  <p>Error in temp[i][, 1] : incorrect number of dimensions</p>
  </blockquote>
  <p>Is there a faster way of doing this than a for loop in R? This is a practice run and I will be potentially importing a lot of files to average over</p>