Skip to content
Prev 334612 / 398506 Next

binary symmetric matrix combination

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),paste0)),value1=as.vector(m1),key='Name1')
d2 <- data.table(Name1=as.vector(outer(rownames(m2),colnames(m2),paste0)),value2=as.vector(m2),key='Name1')
res <- d2[d1]
res1 <- as.data.frame(res)
res1[,3][!is.na(res1[,2])] <- res1[,2][!is.na(res1[,2])]
vec1 <- as.vector(outer(rownames(m1),colnames(m1),paste0))
res2 <- res1[match(vec1,res1[,1]),-2]
res3 <- matrix(res2[,2],dimnames=list(rownames(m1),colnames(m1)),ncol=ncol(m1))


#or

vec1 <- paste0(rownames(m1)[row(m1)],colnames(m1)[col(m1)])
?vec2 <- paste0(rownames(m2)[row(m2)],colnames(m2)[col(m2)])
indx <- match(vec1,vec2)
indx1 <- indx[!is.na(indx)]
?indx2 <- match(vec2,vec1)
indx2N <- indx2[!is.na(indx2)]
?m1[indx2N] <- m2[indx1]



A.K.
On Monday, December 16, 2013 1:54 PM, Elio Shijaku <selius at gmail.com> wrote:
Hi Arun,

I hope you remember me. You helped me build several symmetrical matrices in R. I have one question though. I have now build all the matrices and I want to combine each of them to a larger one. To make the matter simpler to understand, I am attaching the text version of both files. What I would like is to merge the contents of 1991res (574x574 symmetric matrix) into the Test file (4703x4703, symmetric matrix which includes the row names of the 1991res. 

Could you help me by showing the steps I should take to merge the matrices?

Thank you in advance and sorry for disturbing.

Best,

Elio
On Mon, Sep 23, 2013 at 2:19 AM, arun <smartpink111 at yahoo.com> wrote:
Hi Elio,
Message-ID: <1387398838.30801.YahooMailNeo@web142601.mail.bf1.yahoo.com>
In-Reply-To: <CAEBi+_kKjtF7VQuqDAe9EYwYcb+irHGuvJOgT4PCxyRJ6mZPKQ@mail.gmail.com>