Hello! If I have a matrix as 1 2 2 3 and I want to change the value 2 in 0, what can I do? Thank you -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
A[A==2] <- 0 "ambrosini77 at libero.it" wrote:> > Hello! If I have a matrix as 1 2 > 2 3 > and I want to change the value 2 in 0, what can I do? > Thank you > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-- Ole F. Christensen Department of Mathematics and Statistics Fylde College, Lancaster University Lancaster, LA1 4YF, England -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
x <- matrix(c(1,2,2,3)) x[x==2] <- 0 I suggest reading the "Introduction to R" that comes with the R package, it will help you with basic questions like this ... (see "Index vectors; selecting and modifying subsets of a data set") On Mon, 15 Apr 2002, [utf-8] ambrosini77 at libero.it wrote:> Hello! If I have a matrix as 1 2 > 2 3 > and I want to change the value 2 in 0, what can I do? > Thank you > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-- 318 Carr Hall bolker at zoo.ufl.edu Zoology Department, University of Florida http://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hello! This is the situation. I have a file in wich there is a scattered matrix. I give an example: aa bb cc bb xx dd cv st rw xx yu de qw ww zzp where aa is a node that has a path with aa, one with bb, and one with cc. bb has a path with xx, dd has a path with cv, one with st, ... In my experiment I have more or less 100 lines. My nodes are Web pages. I have another file that gives me a wich nodes are related with the query1 query1 0 aa 1 query1 0 cc 0 query1 0 dd 0 query1 0 cv 1 query1 0 rw 0 query1 0 qw 0 query1 0 ww 1 The query1 is not related with all the nodes of the scattered matrix but only with someone. The third column gives me which node is related with query1. This is the most important column. The second column with all "0" is a vector of costant that is useless. The fourth column tells me if the node considered in the second column is relevant to the query or not and also this column is not important for my work. Now, considering the query1, I want to obtain a new scattered matrix where only the nodes related with query1 appears. Starting from the example a have to obtain: aa cc dd cv rw The steps to do are: take the first line of the scattered matrix. If the first node (of the first column) of the row doesn't appear in the list of the nodes related to query, do not consider this line. If the node appears, then look if at least another node in the row is related with query1. Write the lines with all the nodes related with query1, without writing the nodes that are not related with query1. Take the second line and do the same things... Summarizing: starting from the first matrix I want to use the third column of the second matrix to obtain a new one that contains only the nodes that appear in the third column. The output must be a matrix that has at least two elements for row. The most important node is in the first column and so if it doesn't match with the third column of query1, the row is not considered. For example if I have a b c in a row of the matrix and "a" is not a node related with query, the row must not be considered. If a solve this problem I'm in a good point of my thesis. Thank you very much. Excuseme for my english. Alessandro Ambrosini -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hello. I have a vector of about 1000 words. Now I make an example with 5 words. The vector is a b c d e after some works I obtained a matrix with the vector in the first row as aa bb cc dd ee 1 0 1 1 0 After other passage I obtained another vector that has the same words but that not the same order of the first one. I obtained dd ee cc aa bb Now my problem is to find a new matrix starting from the one that I wrote before, changing the position of the columns, according to the order of the second vector. Using the example I want to obtain dd ee cc aa bb 1 0 1 1 0 The real vector is very long and so I can't make change of position of the columns manually. Thank you Alessandro -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 8 May 2002, 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",...Something like all.file.names<-list.files(pattern="data") m2<-read.table("query.txt) qvals<-levels(m2[[3]]) unione<-NULL 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 } and then if you want to concatenate all the results do.call("c", unione) -thomas Thomas Lumley Asst. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi, On Thu, 9 May 2002, Ambrosini Alessandro wrote: |for (filename in all.file.names){ | m1<-read.table(filename,fill=TRUE,header=FALSE) | m1<-m1[m1[,1]%in%qvals,] Cannot you simly check here if there is any rows left in m1? E.g. write something like if(rows(df1) == 0) next | 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 |} Perhaps it helps. Ott -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._