[R] coping zeros from matrix to another
arun
smartpink111 at yahoo.com
Sun May 19 23:48:05 CEST 2013
May be this helps:
set.seed(28)
mat1<- matrix(sample(0:50,20,replace=TRUE),nrow=5)
A<- dist(mat1)
A[2:4]<- 0
set.seed(35)
mat2<- matrix(sample(1:50,20,replace=TRUE),nrow=5)
B<- dist(mat2)
B[which(A==0)]<-0
B
# 1 2 3 4
#2 49.07138
#3 0.00000 28.19574
#4 0.00000 55.70458 33.25658
#5 0.00000 41.97618 31.35283 24.55606
A.K.
----- Original Message -----
From: eliza botto <eliza_botto at hotmail.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc:
Sent: Sunday, May 19, 2013 5:05 PM
Subject: [R] coping zeros from matrix to another
Dear useRs,i have two distance matrices A and B. The distances in A are linked with distances in B. What i want to do is the following...There are some points in A where distances are zero(those points are apart from usual diagonal of zero values).Whereas, in B the distances at those points are not necessarily zeros . i want "0" at those points in B where distance in A is zero. How can i do that??i hope my question is clearthanks indeed in advance,Eliza
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list