[adegenet-forum] Entering a distance matrix
Pip Griffin
pip.griffin at gmail.com
Fri Sep 28 14:47:28 CEST 2012
Hi Ian,
Here is some code that should help:
# This assumes your distance file is in a tab-delimited table format
# also that it has a header, and that the first column contains the
population names
# (or individual names, if you're looking at pairwise distances
between individuals).
initialtable<-read.table("All Pops Pairwise Distance.txt", header=TRUE)
# Getting the population names from Column 1
popnames<-as.vector(initialtable[,1])
# Converting your dataframe into a matrix
# nb exclude the column that contains the population names, you only
want the distances themselves
initialmatrix<-as.matrix(initialtable[,2:ncol(initialtable)])
# Giving your matrix some dimension names (the population names you
specified just before as a vector)
dimnames(initialmatrix)<-list(popnames, popnames)
#Specifying your matrix as a pairwise distance matrix
distmatrix<-as.dist(initialmatrix)
Best of luck!
Pip Griffin
On Fri, Sep 28, 2012 at 1:52 AM, Ian Bradbury <ibradbur at me.com> wrote:
> Hi, I am working with a series of aquatic populations around an island. I am
> hoping to do IBD and other spatial analyses and trying to figure out how to
> deal with complex landscape structure. I can not just use the straight line
> distances and was considering using my own distance matrix but when I load a
> text file (either tab or csv) the format doesn't match. Any suggestions on
> how to load my own distance matrices (gen or geo) would be much appreciated.
> Thanks, Ian
>
>
> _______________________________________________
> adegenet-forum mailing list
> adegenet-forum at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/adegenet-forum
More information about the adegenet-forum
mailing list