title: grep or pmatch?
body: <p>I am trying to import a series of files from directory and convert each of them into a dataframe. I would also like to use the file title to create two new columns with title-dependent values. Input files have the format: <code>xx_yy.out</code>
  Where XX can currently be one of three values. YY currently has two possible values. In the future these numbers will go up.</p>
  
  <hr>
  
  <p>Edit of Solution based on the comments (see below for the original question)</p>
  
  <hr>
  
  <p>edited again to reflect suggestions of @JoshO'Brien</p>
  
  <pre><code>filelist &lt;- as.list(dir(pattern = ".*.out"))
  
  for(i in filelist) {
  
      tempdata  &lt;- read.table(i)                  #read the table
      filelistshort &lt;- gsub(".out$", "", i)       #remove the end of the file
      tempsplit &lt;- strsplit(filelistshort, "_")   #remove the underscore
      xx &lt;- sapply(tempsplit, "[", 1)             #get xx
      yy &lt;- sapply(tempsplit, "[", 2)             #get yy
      tempdata$XX &lt;- xx                           #add XX column
      tempdata$YY &lt;- yy                           #add YY column
      assign(gsub(".out","",i), tempdata)         # give the dataframe a shortened name
  
  }
  </code></pre>
  
  <p>Below is the original code showing that I wanted to use some means to ge teh XX and YY values but wasn't sure of the best way:</p>
  
  <p>My outline (after @romanlustrik <a href="https://stackoverflow.com/questions/4756989/how-to-load-data-quickly-into-r">post</a> ) is as follows:</p>
  
  <pre><code>filelist &lt;- as.list(dir(pattern = ".*.out"))
  lapply(filelist, FUN = function(x) {
      xx &lt;- grep() or pmatch()
      yy &lt;- grep() or pmatch()
      x &lt;- data.frame(read.table(x)) 
      x$colx &lt;- xx
      x$coly &lt;- yy
      return(x)
  })
  </code></pre>
  
  <p>where the <code>xx &lt;-</code>  and <code>yy &lt;-</code> lines would be a lookup based on either pmatch or grep. I am playing around to make either one work but would welcome any suggestions.</p>