web2edges: Conversion of a network matrix into a (weighted) edge list

Description Usage Arguments Details Value Note Author(s) Examples

View source: R/web2edges.R


This helper function converts a bipartite matrix into an edge list, optionally weighted, as used by other packages and software, and writes this to the hard drive (optionally)


web2edges(web, webName=NULL, weight.column=TRUE, both.directions=FALSE, 
	is.one.mode=FALSE, out.files=c("edges", "names", "groups")[1:2],
	return=FALSE, verbose=FALSE)



A matrix with lower trophic level species as rows, higher trophic level species as columns and number of interactions as entries.


An optional name for the data file generated by the function.


Logical; is the web quantitative and should hence a weighted edge list be produced? Defaults to TRUE.


Logical; shall each link be represented twice, i.e. once from A to B and also from B to A? Defaults to FALSE.


Logical; if TRUE, labels for species will be used as they currently are in the web; otherwise, species will be re-labelled so that the first column will have number NROW(web) + 1. This is also the default.


String indicating which files to produce: "edges" writes an edge list, "names" writes a list with names belonging to the edges and "groups" writes a file assigning the species to higher and lower trophic levels. The default produces the edge list and the names file.


Logical; shall the edge list be returned by this function (for future use in R)? Defaults to FALSE. Setting return to TRUE will prevent writing of files to the hard drive!


Logical; shall some feedback tell you that the files have been generated? Defaults to FALSE.


Many network programs (e.g. Pajek) require input in the form of an edge list. Here each species is a number. The edge list has two column, one with the target and one with the origin of the connection. That means an interaction between 1 and 6 would be written (in one line) as: "1 6". In a weighted edge list, a third column represents the strength of the interaction: "1 6 4.77".

All this function does is to transform the typical interaction matrix used in bipartite into an edge list. Within R this could be used e.g. in the package tnet; outside R by Pajek or others.

Similar to as.one.mode this function is there to increase interchange between different coding standards and packages.


A matrix ("edge list") with two (unweighted) or three (weighted) columns.

If return=FALSE, this matrix (and possibly names and groups) are written to a text-file in the working directory.


The function is used as export helper (default) or as link to tnet (with return=TRUE).


Carsten F. Dormann [email protected]



Example output

Loading required package: vegan
Loading required package: permute
Loading required package: lattice
This is vegan 2.4-3
Loading required package: sna
Loading required package: statnet.common
Loading required package: network
network: Classes for Relational Data
Version 1.13.0 created on 2015-08-31.
copyright (c) 2005, Carter T. Butts, University of California-Irvine
                    Mark S. Handcock, University of California -- Los Angeles
                    David R. Hunter, Penn State University
                    Martina Morris, University of Washington
                    Skye Bender-deMoll, University of Washington
 For citation information, type citation("network").
 Type help("network-package") to get started.

sna: Tools for Social Network Analysis
Version 2.4 created on 2016-07-23.
copyright (c) 2005, Carter T. Butts, University of California-Irvine
 For citation information, type citation("sna").
 Type help(package="sna") to get started.

 This is bipartite 2.08
 For latest changes see versionlog in  ?"bipartite-package".
 For citation see: citation("bipartite").
 Have a nice time plotting and analysing two-mode networks.

Attaching package: 'bipartite'

The following object is masked from 'package:vegan':


                         row col edge.weights
Aristotelia chilensis      1  10          673
Alstroemeria aurea         2  11          154
Berberis darwinii          4  11           67
Aristotelia chilensis      1  12          110
Rosa eglanteria            5  12            6
Ribes magellanicum         7  13            2
Alstroemeria aurea         2  14            5
Berberis darwinii          4  14            5
Rosa eglanteria            5  14            4
Alstroemeria aurea         2  15            7
Alstroemeria aurea         2  16            1
Rosa eglanteria            5  16            2
Ribes magellanicum         7  16            3
Calceolaria crenatiflora   9  16            1
Alstroemeria aurea         2  17            3
Alstroemeria aurea         2  18            8
Mutisia decurrens          8  18            1
Aristotelia chilensis      1  19            4
Alstroemeria aurea         2  19            1
Alstroemeria aurea         2  20            1
Cynanchum diemii           6  21            8
Cynanchum diemii           6  22            1
Alstroemeria aurea         2  23            4
Rosa eglanteria            5  23            3
Aristotelia chilensis      1  24            1
Schinus patagonicus        3  24           15
Cynanchum diemii           6  25            2
Calceolaria crenatiflora   9  26            3
Alstroemeria aurea         2  27            4
Cynanchum diemii           6  28            9
Alstroemeria aurea         2  29            1
Alstroemeria aurea         2  30            6
Alstroemeria aurea         2  31            1
Alstroemeria aurea         2  32            1
Aristotelia chilensis      1  33            1
Alstroemeria aurea         2  33            3
Alstroemeria aurea         2  34            4
Alstroemeria aurea         2  35            4
Aristotelia chilensis      1  36            1

bipartite documentation built on May 30, 2017, 1:25 a.m.