Coerces distance matrix to a data.frame object
Symmetrical distance matrix
(TRUE/FALSE) remove matrix diagonal, self values.
data.frame object representing to and from values
Function results in data.frame object with "X1" (FROM), "X2" (TO) and "distance" columns. The FROM column represents to origin ID, TO represents destination ID and distance is the associated matrix distance. These results can be joined back to the graph object using either the origin or destination ID's.
Jeffrey S. Evans <email@example.com> and Melanie Murphy <firstname.lastname@example.org>
1 2 3 4 5 6 7 8 9 10 11 12 13
library(sp) pts <- cbind( x=runif(15, 480933, 504250), y=runif(15, 4479433, 4535122)) pts <- SpatialPointsDataFrame(pts, data.frame(ID=paste("ob",1:nrow(pts),sep=""))) # Create distance matrix dm <- spDists(pts, pts) colnames(dm) <- pts@data[,"ID"] rownames(dm) <- pts@data[,"ID"] # Coerce to data.frame with TO and FROM ID's and associated distance dm.df <- dmatrix.df(dm) head(dm.df)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.