asDF: Convert network to data frame(s)

View source: R/asDF.R

asDFR Documentation

Convert network to data frame(s)

Description

Convert a network data object to, possibly two, data frames: a data frame with an edge list with edge attributes (if any), and a data frame of vertexes with vertex attributes (if any). This is a generic function, see below for available methods.

Usage

asDF(object, ...)

## S3 method for class 'network'
asDF(object, ...)

## S3 method for class 'igraph'
asDF(object, ...)

Arguments

object

R object representing a network, see below for available methods

...

other arguments passed to/from other methods

Details

Currently there are methods for object being in one of the following classes: "network", "igraph".

The function first gets the graph edge list using the appropriate function depending on the class of object (see below). Edge attributes, if any, are then extracted using dumpAttr and added to it.

The vertex data frame is constructed with a vertex id as a sequence of integer numbers. Details are method-specific, see below. Vertex attributes are extracted with dumpAttr and added to this data frame.

Method-specific notes:

For objects of class "network". Objects of this class store the vertex ids as integer numbers. There is also an attribute "vertex.names" which is always created when using graph constructors provided in the package network. asDF adds "vertex.names" to the vertex data frame as a normal attribute and does not use it as a vertex id in the edge list.

The edge list is created using as.matrix.network function and contains integer vertex ids.

Objects of class "igraph", as provided by the igraph package. Vertex ids in these objects integers starting from 1 (in igraph version prior to 0.6-0 vertex ids started from 0). However, it is also possible to provide a vertex attribute "name". It is added to the vertex data frame as a normal vertex attribute and is not used on the edge list data frame.

The edge list is created using get.edgelist function with argument names set to FALSE so that integer vertex ids are used.

Value

List with two components:

edges

containing an edge list data frame at first two columns and edge attributes on further ones.

vertexes

with vertex id in the first column, named id and any vertex attributes in the other columns.

Examples

# using method for 'network' objects
d1 <- asDF(exNetwork)
str(d1)

# using method for 'igraph' objects
d2 <- asDF(exIgraph)
str(d2)

intergraph documentation built on Aug. 21, 2023, 1:06 a.m.