[R] Reading many files at once

Uwe Ligges ligges at statistik.uni-dortmund.de
Sun Sep 3 16:15:54 CEST 2006



Srinivas Iyyer wrote:
> dear group, 
>  
> i have 100 files starting with 'hsa-*'.
> 
> ex. file:
> 
> fruit   p-value 
> ------------
> apple  0.0003
> orange 0.004
> kiwi   0.0003
> peach  0.0004
> 
> 
> 
> I want to read all these files and create a single
> matrix. here each file may have different fruit names.
>  
> in the matrix i want to have a union of all fruits and
> those should be the rows in the matrix and file names
> should be columns. 
> 
> ex;
>         hsa-1   hsa-2  hsa-3  hsa-4  hsa-5
> apple   0.003   0.01   0.002   0.002  0.002
> orange  0.003   0.01   0.002   0.002  0.002
> kiwi    0.003   0.01   0.002   0.002  0.002
> peach   0.003   0.01   0.002   0.002  0.002
> banana  0.003   0.01   0.008   0.002  0.001
> plum    0.003   0.01   0.009   0.002  0.005
> mango   0.003   0.001  0.002   0.002  0.008
> 
>  
> could any one help me please.  


This is a FAQ, more or less, please read the FAQs as the posting guide 
asks you to do.

Use
   myFiles <- list.files( ..., pattern="^hsa-")
to get the filenames, loop ober the files and insert the values into you 
matrix or data.frame.

Uwe Ligges




> thank you.
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list