How can I easily convert this format INT CAB 1.0000000 LIG CAB 0.3333333 TEN CAB 1.0000000 INT LIG 1.0000000 TEN LIG 1.0000000 INT TEN 0.0000000 to this dissimilarity structure format(compatible with hclust) ? CAB INT LIG INT 1.0000000 LIG 0.3333333 1 TEN 1.0000000 0 1 (and vice versa) Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: https://stat.ethz.ch/pipermail/r-help/attachments/20010703/2726ef3a/attachment.html
On Tue, 3 Jul 2001, Francois Deshaies wrote:> How can I easily convert this format > > INT CAB 1.0000000 > LIG CAB 0.3333333 > TEN CAB 1.0000000 > INT LIG 1.0000000 > TEN LIG 1.0000000 > INT TEN 0.0000000 > > to this dissimilarity structure format(compatible with hclust) ? > > CAB INT LIG > INT 1.0000000 > LIG 0.3333333 1 > TEN 1.0000000 0 1 > > (and vice versa)One way is m<-matrix(ncol=4,nrow=4) m[lower.tri(m)]<-your.dissimilarity.vector as.dist(m) In fact, dissimilarity objects are just vectors with some attributes, [unclass() a dist object to see], so you could just put these attributes on your vector. This is stylistically a bad idea, since in theory the internal structure of "dist" objects could change at any time, but it would probably work. -thomas -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> From: Francois Deshaies > > How can I easily convert this format > > INT CAB 1.0000000 > LIG CAB 0.3333333 > TEN CAB 1.0000000 > INT LIG 1.0000000 > TEN LIG 1.0000000 > INT TEN 0.0000000 > > to this dissimilarity structure format(compatible with hclust) ? > > CAB INT LIG > INT 1.0000000 > LIG 0.3333333 1 > TEN 1.0000000 0 1 > > (and vice versa) > > Thanks--------------------------- To convert from the vector to an interaction matrix (which may not be the best form for the dissimilarity matrix...)> xV1 V2 V3 1 INT CAB 1.0000000 2 LIG CAB 0.3333333 3 TEN CAB 1.0000000 4 INT LIG 1.0000000 5 TEN LIG 1.0000000 6 INT TEN 0.0000000> a <- unique (x$V1) > b <- unique (x$V2) > ij <- cbind (match (x$V1, a), match (x$V2, b)) > d <- matrix (0, nrow=length(a), ncol=length(b)) > dimnames(d) <- list (a, b) > d[ij] <- x$V3 > dCAB LIG TEN INT 1.0000000 1 0 LIG 0.3333333 0 0 TEN 1.0000000 1 0 Denis White US EPA, 200 SW 35th St, Corvallis, Oregon, 97333 USA voice: 541.754.4476, email: white.denis at epa.gov web: www.epa.gov/wed/pages/staff/white/ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._