Hi All,

I am using the ape R package to extract interspecific distances from a
pairwise distance matrix.

Consider the woodmouse example.

    library(ape)

    data(woodmouse)

    dists <- dist.dna(woodmouse, model = "raw", as.matrix = TRUE)
    isSymmetric(dists) # TRUE
    dists[upper.tri(dists, diag = FALSE)] <- NA # replace upper triangle
with NA and then subset to get lower triangular matrix
    isSymmetric(dists) # FALSE
    dists # this is a matrix

    labs <- labels(woodmouse) # get species names

    res <- outer(labs, labs, "==") # get cases where matrix elements are
equal
    inter <- na.omit(dists[!res]) # get interspecific distances by taking
elements that are not equal


The problem I am facing is that I need 'inter' to be a matrix instead of a
vector, so that I can tell which distances belong to which pairs of
specimens. The 'inter' matrix should have the same row and column names as
the 'dists' variable. Simply doing

    as.matrix(inter)

will not suffice in this case since row names and column names are not
preserved.

Once I have a matrix of only interspecific distances, I can then find
nearest neighbours for all species in my dataset and continue from there.

I feel it is an easy solution, but something is just not clicking.

Any ideas?

Please let me know if anything is unclear.

Thanks.

Cheers,

Jarrett

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-phylo mailing list - R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/r-sig-phylo@r-project.org/

Reply via email to