[R] dissimilarity structure

Denis White denis at mail.cor.epa.gov
Tue Jul 3 19:16:28 CEST 2001


> 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...)

> x
   V1  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
> d
          CAB 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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list