Sent on Jan 17th but perhaps using the wrong email address. ---------- Forwarded message --------- From: Eliot Miller <eliot.is...@gmail.com> Date: Tue, Jan 17, 2023 at 8:41 AM Subject: Re: [R-sig-phylo] Extracting interspecific distances as a matrix To: Jarrett Phillips <phillipsjarre...@gmail.com> Cc: <r-sig-phylo@r-project.org>
I haven't used the dist.dna function before, so apologies if I'm off base, but I see it returns a distance object. You can simply do dMat <- as.matrix(d) And now it's a matrix of the more familiar form. I haven't used the split function before either, but rows (or columns) can just be extracted with dMat[1,] etc. Cheers, Eliot On Mon, Jan 16, 2023 at 11:06 PM Jarrett Phillips < phillipsjarre...@gmail.com> wrote: > Hello, > > I'm trying to extract interspecific distances from a large distance matrix > using APE. However, my approach returns a vector. > > Consider the following illustrative example: > > library(ape) > data(woodmouse) > > d <- dist.dna(woodmouse, model = "raw") # get p-distance matrix > labs <- labels(woodmouse) # get species names > o <- outer(labs, labs, "==") # this is a matrix > inter <- d[!o] # this is a vector of interspecific distances > > What I need is for 'inter' to be a matrix so I can use split() to split the > matrix into lists by species. > > Simply coercing to a matrix with as.matrix(inter) destroys the structure of > the distance matrix. > > Any assistance is appreciated. > > 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/ > [[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/