Interface between nb and gra format

0th

Percentile

Convert nb and gra format into each other

Convert neighborhood structure objects of class "nb" from R-package spdep to graph objects of class "gra" from R-package R2BayesX and vice versa.

Keywords
spatial
Usage
nb2gra(nbObject)
gra2nb(graObject)
Arguments
nbObject

neighborhood structure object of class "nb"

graObject

graph object of class "gra"

Value

Equivalent object in the other format.

See Also

sp2bnd, bnd2sp for conversion between the geographical information formats and read.gra, write.gra for the interface to the R2BayesX files.

Aliases
  • nb2gra
  • gra2nb
Examples
# NOT RUN {
## first nb to gra:
if(requireNamespace("spdep") &
  requireNamespace("rgdal") &
  requireNamespace("spData")) {
  library("spdep")
  library("spData")
  library("rgdal")

  columbus <- readOGR(system.file("shapes/columbus.shp", package="spData")[1])

  colNb <- poly2nb(columbus)

  ## ... here manual editing is possible ...
  ## then export to graph format
  colGra <- nb2gra(colNb)

  ## and save in BayesX file
  graFile <- tempfile()
  write.gra(colGra, file=graFile)

  ## now back from gra to nb:
  colGra <- read.gra(graFile)
  newColNb <- gra2nb(colGra)
  newColNb

  ## compare this with the original
  colNb

  ## only the call attribute does not match (which is OK):
  all.equal(newColNb, colNb, check.attributes = FALSE)
  attr(newColNb, "call")
  attr(colNb, "call")
}
# }
Documentation reproduced from package R2BayesX, version 1.1-1, License: GPL-2 | GPL-3

Community examples

Looks like there are no examples yet.