title: How to loop over files in different directories
body: <p>I want to loop over multiple files and apply a function to them. The problem is that these files are all in different, but similarly named, directories. The pathway pattern is similar, but the number changes according to what family it's up to.</p>
  
  <p>For example, I have code written as this:</p>
  
  <pre><code>for(i in 1:numfiles) {
      olddata &lt;- read.table(paste("/home/smith/Family", i, "/Family", i, ".txt", sep="\t"),
                            header=T)      
      # FUNCTION GOES HERE
  
      write.table(newdata,
                  paste("/home/smith/Family", i, "/Family", i, "test.txt",
                        sep = ",", quote=F, row.names=F)
  }
  </code></pre>
  
  <p>The problem I have is that the family numbers don't go in numeric order. Some are labeled just with a number (ex: <code>2</code>) and others have a letter appended to that number (ex: <code>1a</code>)</p>
  
  <p>In each family subdirectory (ie Family i) I want to call in the same file (the file name is exactly the same but with the number (i) changed according to what family it refers to). I want to loop over these particular files. For example... For family 1a the file is here: "/home/smith/Family1a/Family1a.txt" but for family 2 the file is here: "/home/smith/Family2/Family2.txt".</p>
  
  <p>Also, R doesn't like my use of <code>numfiles</code>.</p>