Learn R Programming

bipartite (version 2.18)

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

Description

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)

Usage

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

Value

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.

Arguments

web

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

webName

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

weight.column

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

both.directions

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

is.one.mode

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.

out.files

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.

return

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

verbose

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

Author

Carsten F. Dormann carsten.dormann@biom.uni-freiburg.de

Details

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.

Examples

Run this code
data(Safariland)
web2edges(Safariland)
web2edges(as.one.mode(Safariland, project="lower"), is.one.mode=TRUE)

Run the code above in your browser using DataLab