[BioC] txt fille
Steve Lianoglou
mailinglist.honeypot at gmail.com
Thu Mar 12 14:15:01 CET 2009
Hi Joanna,
(Please keep replies on list so others can benefit via the archives
and google)
On Mar 12, 2009, at 8:11 AM, Joanna Zyprych wrote:
> Hi,
> thanks for your help. My problem is exactly so:
> I have 133 files with the name extrpat1.txt, extrpat2.txt, ......,
> extrpat133.txt. These files are in one directory.
> One file I can read in this way:
>
> library(limma)
> m<- read.matrix("C:\\extrpatterns\\extrpat1.txt")
>
> and how can I read all files at the same time?
You can't read them all in at the same time. Why do you wan to? Are
you just trying to make one large matrix out of all 133? Just read
them one by one into a list, then bind the matrices together.
I don't know where the `read.matrix` function is coming from, but
let's assume it works and you want to stack each matrix on top of each
other:
filenames <- dir('/path/to/your/files', pattern='extrpat[:digit:]+\
\.txt$', full.names=TRUE)
# create a list of matrices:
matrices <- lapply(filenames, read.matrix)
# stack them on top of each other, row-wise
my.huge.matrix <- do.call('rbind', matrices)
If this isn't what you're after, could you please explain what you
mean by "reading all files at the same time" and what the end result
is that you are trying achieve?
Thanks,
-steve
>
> Thanks for help
> JOanna
>
> 2009/3/11 Steve Lianoglou <mailinglist.honeypot at gmail.com>
> 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
>
>
>
>
>
>
> --
> as "If we knew what we were doing, it wouldn't be called Research." -
> Albert Einstein
--
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