Learn R Programming

network (version 1.19.0)

as.edgelist: Convert a network object into a numeric edgelist matrix

Description

Constructs an edgelist in a sorted format with defined attributes.

Usage

# S3 method for network
as.edgelist(
  x,
  attrname = NULL,
  as.sna.edgelist = FALSE,
  output = c("matrix", "tibble"),
  ...
)

# S3 method for matrix as.edgelist( x, n, directed = TRUE, bipartite = FALSE, loops = FALSE, vnames = seq_len(n), ... )

# S3 method for tbl_df as.edgelist( x, n, directed = TRUE, bipartite = FALSE, loops = FALSE, vnames = seq_len(n), ... )

is.edgelist(x)

Value

A matrix in which the first two columns are integers giving the tail (source) and head (target) vertex ids of each edge. The matrix will be given the class edgelist.

The edgelist has additional attributes attached to it:

  • attr(,"n") the number of vertices in the original network

  • attr(,"vnames") the names of vertices in the original network

  • attr(,"directed") logical, was the original network directed

  • attr(,"bipartite") was the original network bipartite

  • attr(,"loops") does the original network contain self-loops

Note that if the attrname attribute is used the resulting edgelist matrix will have three columns. And if attrname refers to a character attribute, the resulting edgelist matrix will be character rather than numeric unless output="tibble".

Arguments

x

a network object with additional class added indicating how it should be dispatched.

attrname

optionally, the name of an edge attribute to use for edge values; may be a vector of names if output="tibble"

as.sna.edgelist

logical; should the edgelist be returned in edgelist form expected by the sna package? Ignored if output="tibble"

output

return type: a matrix or a tibble; see as.matrix.network for the difference.

...

additional arguments to other methods

n

integer number of vertices in network, value passed to the 'n' flag on edgelist returned

directed

logical; is network directed, value passed to the 'directed' flag on edgelist returned

bipartite

logical or integer; is network bipartite, value passed to the 'bipartite' flag on edgelist returned

loops

logical; are self-loops allowed in network?, value passed to the 'loops' flag on edgelist returned

vnames

vertex names (defaults to vertex ids) to be attached to edgelist for sna package compatibility

Details

Constructs a edgelist matrix or tibble from a network, sorted tails-major order, with tails first, and, for undirected networks, tail < head. This format is required by some reverse-depending packages (e.g. ergm)

The as.matrix.network.edgelist provides similar functionality but it does not enforce ordering or set the edgelist class and so should be slightly faster.

is.edgelist tests if an object has the class 'edgelist'

See Also

See also as.matrix.network.edgelist

Examples

Run this code

   data(emon)
   as.edgelist(emon[[1]])
   as.edgelist(emon[[1]],output="tibble")
   # contrast with unsorted columns of
   as.matrix.network.edgelist(emon[[1]])
  

Run the code above in your browser using DataLab