Hi Jarrett, If you have a vector of species names (say 'taxa'), then:
o <- outer(taxa, taxa, "==") returns a logical matrix with TRUE when the two strings in 'taxa' are the same, FALSE if they are different (so the diagonal is TRUE). Since you return the output of dist.dna() as a matrix, then you can do: diag(o) <- FALSE anoDist[o] # all the intraspecific distances anoDist[!o] # all the interspecific distances You may have also to remove the duplicated distances, maybe with lower.tri(). An alternative is to work with the "dist" object (this will use less memory too) from dist.dna: o <- as.dist(outer(taxa, taxa, "==")) will drop the upper triangle and the diagonal of the logical matrix. The two above commands are the same. After, you can elaborate on this by creating your function(s) if you want to focus on a particular species (or pair of), eg: f <- function(x, y) x == "Homo sapiens" & y == "Homo abilis" o <- as.dist(outer(taxa, taxa, f)) See also the function adegeneet::pairDistPlot() which a method for "DNAbin" objects. HTH Best, Emmanuel ----- Le 19 Oct 22, à 1:16, Jarrett Phillips phillipsjarre...@gmail.com a écrit : > Hello, > > I'm wondering whether someone knows of an efficient way to extract > intraspecific (within-species) and interspecific (between-species) genetic > distances for each species returned by ape::dist.dna() to be able to > calculate the DNA barcode gap. > > It seems extracting the entire object as a matrix is a step in the right > direction. > > Consider the following example: > > library(ape) > library(spider) > > data(anoteropsis) # sample dataset > anoDist <- dist.dna(anoteropsis, model = "raw", pairwise.deletion = > FALSE, as.matrix = TRUE) # compute p-distances > > Any ideas? > > [[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/ _______________________________________________ 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/