[R] Looping over files

Debs Majumdar debs_stata at yahoo.com
Wed Dec 21 02:32:11 CET 2011


Hi,

 I have a list of files in one of my working directories:

"chr17.chunk1.dose.fvd" 

"chr17.chunk1.dose.fvi" 
"chr17.chunk1.prob.fvd"  

"chr17.chunk1.prob.fvi"  

...........

.........
........

"chr17.chunk10.dose.fvd" 

"chr17.chunk10.dose.fvi"
"chr17.chunk10.prob.fvd" 

"chr17.chunk10.prob.fvi"

And I am using the *.dose files to convert the data into a text file.

For a singlefile, the following works:
chr17chunk1dose <- databel("chr17.chunk1.dose")

databel2text(databel=chr17chunk1dose, file="chr1_chunk1.dose.txt", NAString="NA", row.names=TRUE, col.names=TRUE, transpose=FALSE)

I am trying to do the conversion inside a loop for all the files at a time but can't figure out how to do it. Any hep is appreciated.

#### I am trying something like this:

flies <- list.files(pattern="dose")    
for(i in files){
    dose <- databel(i)[[1]]
    databel2text <- (databel = dose,  file="chr17_chunk1.dose.txt", NAString="NA", row.names=TRUE, col.names=TRUE, transpose=FALSE)
    }          


########



Thanks,

Debs




More information about the R-help mailing list