Hello! Two questions: 1: I have to import a matrix of adjacency from a file of a software that is not R (for example "bloc notes" of Windows). The problem is that the matrix is not in the explicit form as 0 1 1 1 0 0 1 0 0 but it is a scattered matrix where in each row there are two nodes that have a direct path. The matrix is a b a c b a c a For example, the first row exspress that node a and node b are connected by a direct line. Can R transform this matrix in the first matrix that I wrote ? Are there any struments? 2: Which is the max dimension of a matrix that R can use (1000X1000?, 500000X500000?)? What is the biggest dimension of a file that R can import? Thank you so much. 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
"Ambrosini Alessandro" <klavan at tiscalinet.it> writes:> Hello! Two questions: > > 1: I have to import a matrix of adjacency from a file of a software that is > not R (for example "bloc notes" of Windows). The problem is that the matrix > is not in the explicit form as > 0 1 1 > 1 0 0 > 1 0 0 > but it is a scattered matrix where in each row there are two nodes that have > a direct path. > The matrix is > > a b > a c > b a > c a > > For example, the first row exspress that node a and node b are connected by > a direct line. > Can R transform this matrix in the first matrix that I wrote ? Are there any > struments?Use matrix indexing: i <- matrix(c(1,2, 1,3, 2,1, 3,1),ncol=2,byrow=T) m <- matrix(0,3,3) m[i] <- 1 m> 2: Which is the max dimension of a matrix that R can use (1000X1000?, > 500000X500000?)? What is the biggest dimension of a file that R can import?It has to fit in available memory. On a 32 bit machine, you can only address 4GB (and only if the OS allows), so in principle the workspace holds 500 million double cells which would allow a 20000x20000 matrix. However, you generally need to have room for several copies, so 5k x 5k sounds more realistic. I forget what current status is on 64-bit architectures. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
question 1: Try this:> list <- cbind(c(1,1,2,3),c(2,3,1,1)) > list[,1] [,2] [1,] 1 2 [2,] 1 3 [3,] 2 1 [4,] 3 1> mat <- matrix(0,max(list),max(list)) > mat[list] <- 1 > mat[,1] [,2] [,3] [1,] 0 1 1 [2,] 1 0 0 [3,] 1 0 0 Now you just need to figure out how to get R to read an ascii file, and convert the a's and b's to 1's and 2's etc. (I don't know how to do this off the top of my head, but you might look at "read" and look for some kind of recoding function) question2: I believe the dimension size limited only by available memory. dave r. On Thu, 18 Apr 2002, Ambrosini Alessandro wrote:> Hello! Two questions: > > 1: I have to import a matrix of adjacency from a file of a software that is > not R (for example "bloc notes" of Windows). The problem is that the matrix > is not in the explicit form as > 0 1 1 > 1 0 0 > 1 0 0 > but it is a scattered matrix where in each row there are two nodes that have > a direct path. > The matrix is > > a b > a c > b a > c a > > For example, the first row exspress that node a and node b are connected by > a direct line. > Can R transform this matrix in the first matrix that I wrote ? Are there any > struments? > > 2: Which is the max dimension of a matrix that R can use (1000X1000?, > 500000X500000?)? What is the biggest dimension of a file that R can import? > > Thank you so much. > 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Thu, 18 Apr 2002, Ambrosini Alessandro wrote:> Hello! Two questions: > > 1: I have to import a matrix of adjacency from a file of a software that is > not R (for example "bloc notes" of Windows). The problem is that the matrix > is not in the explicit form as > 0 1 1 > 1 0 0 > 1 0 0 > but it is a scattered matrix where in each row there are two nodes that have > a direct path. > The matrix is > > a b > a c > b a > c a >after doing a little research, I have discovered "charmatch" which will give the indices of the matches between two sets of strings. For instance:> list1 <- c("a","b","c","d") > list2 <- c("d","d","b") > charmatch(list2,list1)[1] 4 4 2 Using this you can convert a list of letters to a list of numbers. For instance:> rowlist <- c("a","a","b","c") > collist <- c("b","c","a","a") > uniquelist <- sort(unique(c(rowlist,collist))) > uniquelist[1] "a" "b" "c"> rownums <- charmatch(rowlist,uniquelist) > colnums <- charmatch(collist,uniquelist) > list <- cbind(rownums,colnums) > listrownums colnums [1,] 1 2 [2,] 1 3 [3,] 2 1 [4,] 3 1> n <- length(uniquelist) > mat <- matrix(0,n,n) > mat[list] <- 1 > mat[,1] [,2] [,3] [1,] 0 1 1 [2,] 1 0 0 [3,] 1 0 0 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 Thu, 18 Apr 2002, Ambrosini Alessandro wrote:> Hello! Two questions: > > 1: I have to import a matrix of adjacency from a file of a software that is > not R (for example "bloc notes" of Windows). The problem is that the matrix > is not in the explicit form as > 0 1 1 > 1 0 0 > 1 0 0 > but it is a scattered matrix where in each row there are two nodes that have > a direct path. > The matrix is > > a b > a c > b a > c aone more thing: here's how to read from a text file into a matrix of strings so that you can use my charmatching solution:> lines <- readLines("textfile.txt") > lines[1] "a b" "a c" "b a" "c a"> chars <- c(strsplit(lines," "),recursive=TRUE) > chars[1] "a" "b" "a" "c" "b" "a" "c" "a"> chars <- t(matrix(chars,2,length(chars)/2)) > chars[,1] [,2] [1,] "a" "b" [2,] "a" "c" [3,] "b" "a" [4,] "c" "a">dave r. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 Thu, 18 Apr 2002, Ambrosini Alessandro wrote:> Hello! Two questions: > > 1: I have to import a matrix of adjacency from a file of a software that is > not R (for example "bloc notes" of Windows). The problem is that the matrix > is not in the explicit form as > 0 1 1 > 1 0 0 > 1 0 0 > but it is a scattered matrix where in each row there are two nodes that have > a direct path. > The matrix is > > a b > a c > b a > c a >I would use table():> d1 <- c("a","a","b","c") > d2 <- c("b","c","a","a") > table(d1,d2)d2 d1 a b c a 0 1 1 b 1 0 0 c 1 0 0 But is this not a very unefficient way of storing adjacencies? Agus Dr. Agustin Lobo Instituto de Ciencias de la Tierra (CSIC) Lluis Sole Sabaris s/n 08028 Barcelona SPAIN tel 34 93409 5410 fax 34 93411 0012 alobo at ija.csic.es -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._