dmatrix.df: Distance matrix to data.frame

Description Usage Arguments Value Note Author(s) Examples

View source: R/dmatrix.df.R

Description

Coerces distance matrix to a data.frame object

Usage

1
dmatrix.df(x, rm.diag = TRUE)

Arguments

x

Symmetrical distance matrix

rm.diag

(TRUE/FALSE) remove matrix diagonal, self values.

Value

data.frame object representing to and from values

Note

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.

Author(s)

Jeffrey S. Evans <jeffrey_evans@tnc.org> and Melanie Murphy <melanie.murphy@uwyo.edu>

Examples

 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)

GeNetIt documentation built on April 1, 2020, 5:08 p.m.

Related to dmatrix.df in GeNetIt...