[R] how to process multiple data files using R loop

Rolf Turner r.turner at auckland.ac.nz
Sat Aug 9 04:49:20 CEST 2014


On 09/08/14 06:25, Fix Ace wrote:
> I have 16 files and would like to check the information of their first two lines, what I did:
>
>
>> ls(pattern="P_")
>   [1] "P_3_utr_source_data"               "P_5_utr_source_data"
>   [3] "P_exon_per_gene_cds_source_data"   "P_exon_per_gene_source_data"
>   [5] "P_exon_source_data"                "P_first_exon_oncds_source_data"
>   [7] "P_first_intron_oncds_source_data"  "P_first_intron_ongene_source_data"
>   [9] "P_firt_exon_ongene_source_data"    "P_gene_cds_source_data"
> [11] "P_gene_source_data"                "P_intron_source_data"
> [13] "P_last_exon_oncds_source_data"     "P_last_exon_ongene_source_data"
> [15] "P_last_intron_oncds_source_data"   "P_last_intron_ongene_source_data"

<SNIP>

Point of order:  You do ***NOT*** have 16 files as it stands.  The 
output from ls() indicates that you have 16 ***objects*** (presumably 
data frames) in your "work space" or "global environment".  (If the data 
were originally in 16 separate files, these files have apparently 
already been read into R.)

If you are going to use R, learn to distinguish the relevant concepts 
and to use the appropriate terminology.  Otherwise you will confuse 
everyone, including yourself, and get things totally wrong.  It is 
really no more difficult to use correct terminology than it is to use 
incorrect terminology --- and the former has the advantage of not 
misleading all concerned.


Dave Winsemius has already told you how to solve your immediate problem, 
using get().

cheers,

Rolf Turner


-- 
Rolf Turner
Technical Editor ANZJS



More information about the R-help mailing list