Wednesday, 11 September 2013

How to loop over files in different directories [R]

How to loop over files in different directories [R]

So, I've set up a loop... however, my files that I want to loop over (say
10) are all in different directories, but the pathway pattern is similar
except the number changes according to what family its up to.
For example, I have code written as this:
for(i in 1:numfiles) {
olddata <-
read.table(paste("/home/smith/Family",i,"/Family",i,".txt",sep="\t"),header=T)
Some code
write.table(newdata,(paste("/home/smith/Family",i,"/Family",i,"test.txt",sep=",",quote=F,row.names=F)
}
The only problem I have is that the family numbers don't go in numeric
order. Some are labeled just with a number (say, 2) and others have a
letter appended to that number (say, 1a)
First, it doesn't like "numfiles" and also I'm being told there is a extra
squiggly bracket at the end of my code. I have written a function in my
"some code" so not sure whether this could be the problem.
I'm relative new to R so any help will be greatly appreciated

No comments:

Post a Comment