Re: [R] binary symmetric matrix combination

2013-12-18 Thread arun
Hi, You could try: Either: dat1 <- read.table("Test.txt",header=TRUE) dim(dat1) #[1] 4735 4735 dat2 <- read.table("1991res.txt",header=TRUE) dim(dat2) #[1] 574 574 m1 <- as.matrix(dat1) m2 <- as.matrix(dat2) library(data.table) d1 <- data.table(Name1=as.vector(outer(rownames(m1),colnames(m1),past

Re: [R] binary symmetric matrix combination

2013-09-21 Thread arun
Hi Elio, Use ?write.table() write.table(res,"Eliores.txt",quote=FALSE) #and as read the file mat1<- as.matrix(read.table("Eliores.txt",header=TRUE)) #or even this should work mat1<-  as.matrix(read.table("Eliores.txt")) #If you have very big matrix, you may try: library(tseries) write(res,"Elior

Re: [R] binary symmetric matrix combination

2013-09-20 Thread supernovartis
Hi Arun, I get the following error when I enter the command: library(reshape2) Error in library(reshape2) : there is no package called ‘reshape2’ Any ideas? Thanks again. On Fri, Sep 20, 2013 at 3:09 PM, arun kirshna [via R] < ml-node+s789695n4676569...@n4.nabble.com> wrote: > Hi Eli

Re: [R] binary symmetric matrix combination

2013-09-20 Thread arun
Hi Elio, Try this: library(stringr) lines1<-str_trim(gsub("\t"," ",readLines("elio.txt")))  lst1<-lapply(split(lines1,cumsum(lines1=="")),function(x) x[x!=""]) lst2<- lapply(lst1[lapply(lst1,length)>0],function(x) as.matrix(read.table(text=x,row.names=1))) names(lst2)<- paste0("m",seq_along(lst

Re: [R] binary symmetric matrix combination

2013-09-19 Thread supernovartis
Hi Arun, Worked perfectly, one last question how to read the matrices which have the dollar sign? Thanks again. On Thu, Sep 19, 2013 at 3:46 PM, arun kirshna [via R] < ml-node+s789695n4676510...@n4.nabble.com> wrote: > Hi Elio, > Try this: > library(stringr) > lines1<-str_trim(gsub("\t"," ",r

Re: [R] binary symmetric matrix combination

2013-09-19 Thread arun
Hi Elio, Try this: library(stringr)  lines1<-str_trim(gsub("\t"," ",readLines("elio.txt")))  lst1<-lapply(split(lines1,cumsum(lines2=="")),function(x) x[x!=""]) lst2<- lapply(lst1[lapply(lst1,length)>0],function(x) as.matrix(read.table(text=x,row.names=1))) names(lst2)<- paste0("m",seq_along(lst2

Re: [R] binary symmetric matrix combination

2013-09-18 Thread supernovartis
Hi, I have another question related to the same problem. I have a text file with about 350 matrices each separated by a blank row. My question is how to make R believe each matrix is separate and has a specific name m1, m2,m350. Below is an example: aa5 aa10 b253 b254 aa5 0 1 1 1 aa10 1 0

Re: [R] binary symmetric matrix combination

2013-09-18 Thread arun
Hi Elio, Try this: Assuming that there is a single blank row separating the matrices: lines1<- readLines(textConnection("aa5     aa10     b253     b254 aa5     0     1     1     1 aa10     1     0     1     1 b253     1     1     0     1 b254     1     1     1     0     aa5     aa9     b27    

Re: [R] binary symmetric matrix combination

2013-09-06 Thread arun
HI, No problem.  Suppose you have many matrices and you want to sum up the repeated variables, may be this helps: #Creating one more matrix which has some repeated variables. m6<- as.matrix(read.table(text="y1 e5 s2  y1 0 1 1  e5 1 0 1  s2 1 1 0",sep="",header=TRUE)) #m1:m5 same as previous dat

Re: [R] binary symmetric matrix combination

2013-09-05 Thread arun
Hi, May be this helps: m1<- as.matrix(read.table(text=" y1 g24 y1 0 1 g24 1 0 ",sep="",header=TRUE)) m2<-as.matrix(read.table(text="y1 c1 c2 l17  y1 0 1 1 1  c1 1 0 1 1  c2 1 1 0 1  l17 1 1 1 0",sep="",header=TRUE)) m3<- as.matrix(read.table(text="y1 h4    s2 s30  y1 0 1 1 1  h4 1 0 1 1  s2 1

Re: [R] binary symmetric matrix combination

2013-09-05 Thread arun
HI, No problem. I think you didn't run the `vecOut` after adding the new matrix.  `lst1` is based on `vecOut` For example: m5<- as.matrix(read.table(text="y1 e6 l16  y1 0 1 1 e6 1 0 1 l16 1 1 0",sep="",header=TRUE)) names1<-unique(c(colnames(m1),colnames(m2),colnames(m3),colnames(m4), colnames(m5

Re: [R] binary symmetric matrix combination

2013-09-05 Thread arun
Also, some of the steps could be reduced by: names1<-unique(c(colnames(m1),colnames(m2),colnames(m3),colnames(m4))) Out3<-matrix(0,length(names1),length(names1),dimnames=list(names1,names1)) lst1<-sapply(paste0("m",1:4),function(x) {x1<- get(x); x2<-paste0(colnames(x1)[col(x1)],rownames(x1)[row(x