# [R] Problem

Ambrosini Alessandro klavan at tiscalinet.it
Thu May 9 16:26:21 CEST 2002

```Hello.
I have a lot of external file, more or less 1000. Everyone has this form:

a b c d
d f g h
c v n b
.
.
.

I have another file called "query", made in this way

x1 0 a
x1 0 n
x1 0 s
x1 0 c
.
.
.

I have this procedure:

all.file.names<-list.files(pattern="^out")
m2 <- read.table("query.txt")
qvals<-levels(m2[[3]])
unione<-list()

for (filename in all.file.names){
m1<-read.table(filename,fill=TRUE,header=FALSE)
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]))
unione[[filename]]<-m1c
}

It takes the first column of the first type of file and the third column of
the file "query", it makes a comparison and give me a list that has only the
lines of the first file that has got the first element of the row that is
present also in the third column of file "query. It goes on taking lines
that has at least two elements for row that appears in "query". I have to do
it for all my 1000 files and so I use the command "for".
At the end I add all the lines that I found:

x<-do.call("c", unione)

The PROBLEM is this: when there is no word of the first column of the first
file that is also in the third column of "query",  after
"m1<-m1[relnodes>1,]" it apperas "subscript out of bounds" and my output is
always NULL even if I know that there would be some lines.
I want to ask you if there is a way, using "for", to make the comparison of
the 1000 files with the "query" and to obtain a vector that contains the
names of the file that have at least a line with the first element that
match with "query".

SUMMARIZING: if the file has some first elements of some row that appears in
"query", then put it in a list of files that I will use in the future. If
there is no element, don't consider this file.

Thank you
Alessamdro

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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