title: Import data in R from multiple files with name pattern
body: <p>I have a list of files in CSV format, for example: </p>
  
  <blockquote>
    <p>20150507.csv</p>
  </blockquote>
  
  <pre><code>a,10 
  b,20 
  c,30 
  </code></pre>
  
  <blockquote>
    <p>20150506.csv</p>
  </blockquote>
  
  <pre><code>a,100 
  b,20 
  c,1 
  </code></pre>
  
  <p>and so on. I have a text file containing variable names: </p>
  
  <blockquote>
    <p>list.txt</p>
  </blockquote>
  
  <pre><code>a 
  b 
  c 
  d 
  </code></pre>
  
  <p>I need to import the data in such a way that I have values for the variables in the <code>list.txt</code> file: </p>
  
  <pre><code>a: 10, 100,... 
  b: 20, 20, ... 
  c: 30, 1, ... 
  </code></pre>
  
  <p>Values of elements (from <code>list.txt</code>) are searched from all CSV files that match the date name pattern, and after collecting all the values, I need to compute the mean and SD of each variable, and mark observations that are more than 2 SD away from the mean as outliers.  </p>
  
  <p>Currently I am using <code>bash</code> commands to create statistics for each element of <code>list.txt</code> and then load data in R. </p>
  
  <pre><code>for i in `cat list.txt |cut -d, -f1`; do echo "$i";grep "^$i" 2015* | cut -d: -f2 &gt; /tmp/$i.stat;done 
  </code></pre>
  
  <p>and then use a <code>for</code> loop in R to find outliers: </p>
  
  <pre><code>files=list.files(path="/tmp/",pattern=".stat")
  
  for( i in 1:length( files)){
      myfunction(paste("/tmp/",files[[i]],sep='')
  }
  
  myfunction(filename)
      {df &lt;- read.csv(filename, header=F); 
      names(df)=c("symbol","num");
  
      x=df[abs(df$num-mean(df$num))&gt;2*sd(df[,2]),];outl=(nrow(x)/nrow(df))*100;if(outl&gt;1){cat(filename,"\n");
  
      cat("outliers=",outl);cat("\n\n") 
  </code></pre>
  
  <p>However I would like to do the whole process in R only rather than creating multiple files through <code>bash</code> and then read them using a <code>for</code> loop.</p>
  
  <p>I read <a href="https://stat.ethz.ch/R-manual/R-devel/library/base/html/grep.html" rel="nofollow">this grep manual for R</a> , however searching multiple file options does not show up.</p>
  
  <h2>Edit:</h2>
  
  <p>Instead of using <code>for</code>,  I have now used: </p>
  
  <pre><code>df &lt;- do.call(rbind, lapply(list.files(path="/tmp/",pattern = "*.stat"), read.csv,header=FALSE)) 
  </code></pre>
  
  <p>which looks like a better way. </p>
  
  <p>However <code>df2 &lt;- do.call(rbind, lapply(list.files(path="/orignal/dir/",pattern = "2015*.abc.csv"), read.csv,header=FALSE))</code> doesnt make R understand that I'm searching for all files with names starting with 2015* and ending with abc.csv</p>