Dear altogether, I want to blank the lower (or upper) part of a correlation matrix as it is done by dist() example: ( d <- cor(matrix(runif(12),nrow=4)) ) If I do the following d[lower.tri(d)] <- "" of course everything is changed to character - that's not what should be. Additionally, it does not work to assign "0" or anything else. The same is true for assigning "NA". However, what I want is like the following: ( dist(matrix(runif(12),nrow=4)) ) Looking into dist(), it seems that the calculation and the matrix are done in C and not in plain R. How can I realize it? thanks! best, leo
You can try as.dist(d) Christos Hatzis, Ph.D. Nuvera Biosciences, Inc. 400 West Cummings Park Suite 5350 Woburn, MA 01801 Tel: 781-938-3830 www.nuverabio.com> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Leo G?rtler > Sent: Wednesday, February 07, 2007 1:36 PM > To: r-help at stat.math.ethz.ch > Subject: [R] blank upper or lower triangle of cor-matrix > > Dear altogether, > > I want to blank the lower (or upper) part of a correlation > matrix as it is done by dist() > > example: > > ( d <- cor(matrix(runif(12),nrow=4)) ) > > If I do the following > > d[lower.tri(d)] <- "" > > of course everything is changed to character - that's not > what should be. > Additionally, it does not work to assign "0" or anything > else. The same is true for assigning "NA". > > However, what I want is like the following: > > ( dist(matrix(runif(12),nrow=4)) ) > > Looking into dist(), it seems that the calculation and the > matrix are done in C and not in plain R. > > How can I realize it? > > thanks! > > best, > > leo > > ______________________________________________ > R-help at stat.math.ethz.ch 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. > >
And if you want to know how it is done, take a look at stats:::print.dist -Christos> -----Original Message----- > From: Christos Hatzis [mailto:christos at nuverabio.com] > Sent: Wednesday, February 07, 2007 2:16 PM > To: 'Leo G?rtler'; 'r-help at stat.math.ethz.ch' > Subject: RE: [R] blank upper or lower triangle of cor-matrix > > You can try > > as.dist(d) > > > Christos Hatzis, Ph.D. > Nuvera Biosciences, Inc. > 400 West Cummings Park > Suite 5350 > Woburn, MA 01801 > Tel: 781-938-3830 > www.nuverabio.com > > > > > -----Original Message----- > > From: r-help-bounces at stat.math.ethz.ch > > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Leo G?rtler > > Sent: Wednesday, February 07, 2007 1:36 PM > > To: r-help at stat.math.ethz.ch > > Subject: [R] blank upper or lower triangle of cor-matrix > > > > Dear altogether, > > > > I want to blank the lower (or upper) part of a correlation > matrix as > > it is done by dist() > > > > example: > > > > ( d <- cor(matrix(runif(12),nrow=4)) ) > > > > If I do the following > > > > d[lower.tri(d)] <- "" > > > > of course everything is changed to character - that's not > what should > > be. > > Additionally, it does not work to assign "0" or anything else. The > > same is true for assigning "NA". > > > > However, what I want is like the following: > > > > ( dist(matrix(runif(12),nrow=4)) ) > > > > Looking into dist(), it seems that the calculation and the > matrix are > > done in C and not in plain R. > > > > How can I realize it? > > > > thanks! > > > > best, > > > > leo > > > > ______________________________________________ > > R-help at stat.math.ethz.ch 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. > > > >