[R] Problem

Alberto Murta amurta at ipimar.pt
Wed May 8 22:05:43 CEST 2002


Hi

If in that directory you don't have any other files than the ones you
want to use, you can make an object called 'file.names' with the names
of your input files:

> file.names <- system("ls", intern=TRUE)  

if you are using windows then instead of 'ls' should be 'dir'.
Then a 'for' loop should solve your problem:

> for(i in file.names){
	m1 <- read.table(i, fill=TRUE, header=FALSE)
	etc... 
	} 

Cheers

Alberto

 
Tomei Lodino wrote:
> 
> Hi! This is the situation.
> I have these commands. I have not to change anything in these lines but I
> write them to make you understand the situation.
> 
> m1<-read.table("data",fill=TRUE,header=FALSE)
> m2<-read.table("query.txt)
> qvals<-levels(m2[[3]])
> m1<-m1[m1[,1]%in%qvals,]
> relnodes<-apply(m1,1,function(x)sum(x%in%qvals))
> m1<-m1[relnodes>1,]
> m1b<-as.list(as.data.frame(t(as.matrix(m1))))
> m1c<-lapply(m1b,function(x)as.character(x[x%in%qvals]))
> 
> These lines import the external file "data", they make some things and give
> me a output.
> Now my problem is that  I have more or less 100 files. Everytime I take a
> file, I call it m1 and I go on. When I obtain an output, a write
> unione<-(unione,m1c) to update the output given before. (before starting the
> first time I do unione<-NULL)
> Now,  I want to know if there is some commands that repeat all the lines
> written before, taking one by one all the 100 files that I have to use.
> Maybe I can use the "for" command, but in which way?
> Summarizing I have to do 100 times the lines written before, changing
> everytime the name of the external file.
> All the files are in the same directory. The file in m2 is the same for all
> the iterations and so I have not to change it.
> The names of the files are "dataa","datab","datac",...
> Thank you very much.
> Linda
> 


-- 
                           Alberto G. Murta                      
           IPIMAR - Institute of Fisheries and Sea Research
            Avenida de Brasilia, 1449-006 Lisboa, Portugal       
Tel:+351 213027062; Fax:+351 213015849; http://www.ipimar.pt/pelagicos/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list