[BioC] txt fille

Steve Lianoglou mailinglist.honeypot at gmail.com
Wed Mar 11 22:57:51 CET 2009


Hi Joanna,

On Mar 11, 2009, at 5:39 PM, Joanna Zyprych wrote:

> Hallo all,
> I have one problem with read the .txt data. I have to read 133 txt.  
> file in
> R and do some operation on this data. I can't find the function  
> which can do
> this. Could you help me with this? It will be great.

It's not clear what the exact problem you're having is, but let's see:

You are trying to read in 133 different text files, and want to  
perform some function on each? The data in text data, I'm assuming, is  
somehow tabular?

Basically:
(1) go to your data directory
(2) read in each file one at at time
(2) do your calc on the file
(3) go to 2

Here's a simple example. Let's assume all of your data files are tab  
delimited, end with "*dat.txt", live in one particular directory, and  
you need to store one value of a particular calculation for each data  
file.

More or less, you can do:

setwd('/path/to/your/data/directory')
filenames <- dir('.', pattern='dat\\.txt$')
my.results <- numeric(length(filenames))

for (i in seq_along(filenames)) {
   # you might want to set `header` to TRUE depending on your
   # data, see ?read.table
   dat <- read.table(filenames[i], sep='\t')
   # do.some.calculation is a function of your own making
   my.results[i] <- do.some.calculation(dat)
}

Hope that helps,

-steve


--
Steve Lianoglou
Graduate Student: Physiology, Biophysics and Systems Biology
Weill Medical College of Cornell University

http://cbio.mskcc.org/~lianos



More information about the Bioconductor mailing list