Learn R Programming

intergraph (version 1.2-0)

intergraph-package: Coercion routines for network data objects in R

Description

This package contains methods for coercion between various classes used to represent network data in R.

Arguments

Details

Functions implemented in this package allow to coerce (i.e., convert) network data between classes provided by other R packages. Currently supported packages are: network, igraph (versions prior to 0.6, see Note below). The main functions are:
  • as.networkand its methodas.network.igraphto create objects of class "network".
  • as.igraphand its methods to create objects of class "igraph".
See their help pages for more information and examples. As all the supported packages are written using S3 methods, so are the methods in this package. This may change in the future. If you find this package useful in your work please cite it. Type citation(package="intergraph") for the information how to do that.

Examples

Run this code
# example of converting objects between classes 'network' and 'igraph'

if( require(network) & require(igraph0) )
{

  ### convert 'network' -> 'igraph'

  # example network
  summary(exNetwork)

  # convert to igraph
  g <- as.igraph(exNetwork)

  # check if 'exNetwork' and 'g' are the same
  all.equal( as.matrix(exNetwork, "edgelist"), 
    igraph0::get.edgelist(g) + 1 )   
    # +1 because igraph's vertex ids start from 0

  # compre results using 'netcompare'
  netcompare(exNetwork, g)

  ### convert 'igraph' -> 'network'

  # example network: same as above but of class 'igraph'
  summary(exIgraph)

  # convert to network class
  gg <- as.network(exIgraph)

  # check if they are the same
  all.equal( get.edgelist(exIgraph), as.matrix(gg, "edgelist"))
  # compre results using 'netcompare'
  netcompare(exIgraph, g)
}

Run the code above in your browser using DataLab