These functions convert relational data in matrix form to network edge sets.

1 2 3 4 | ```
network.adjacency(x, g, ignore.eval = TRUE, names.eval = NULL, ...)
network.edgelist(x, g, ignore.eval = TRUE, names.eval = NULL, ...)
network.incidence(x, g, ignore.eval = TRUE, names.eval = NULL, ...)
network.bipartite(x, g, ignore.eval = TRUE, names.eval = NULL, ...)
``` |

`x` |
a matrix containing edge information |

`g` |
an object of class |

`ignore.eval` |
logical; ignore edge value information in x? |

`names.eval` |
a name for the edge attribute under which to store edge values, if any |

`...` |
possible additional arguments (such as |

Each of the above functions takes a `network`

and a matrix as input, and modifies the supplied `network`

object by adding the appropriate edges. `network.adjacency`

takes `x`

to be an adjacency matrix; `network.edgelist`

takes `x`

to be an edgelist matrix; and `network.incidence`

takes `x`

to be an incidence matrix. `network.bipartite`

takes `x`

to be a two-mode adjacency matrix where rows and columns reflect each respective mode (conventionally, actors and events); If `ignore.eval==FALSE`

, (non-zero) edge values are stored as edgewise attributes with name `names.eval`

. The `edge.check`

argument can be added via `...`

and will be passed to `add.edges`

.

Edgelist matrices to be used with `network.edgelist`

should have one row per edge, with the first two columns indicating the sender and receiver of each edge (respectively). Edge values may be provided in additional columns. The edge attributes will be created with names corresponding to the column names unless alternate names are provided via `names.eval`

. The vertices specified in the first two columns, which can be characters, are added to the network in default sort order. The edges are added in the order specified by the edgelist matrix.

Incidence matrices should contain one row per vertex, with one column per edge. A non-zero entry in the matrix means that the edge with the id corresponding to the column index will have an incident vertex with an id corresponding to the row index. In the directed case, negative cell values are taken to indicate tail vertices, while positive values indicate head vertices.

Results similar to `network.adjacency`

can also be obtained by means of extraction/replacement operators. See the associated man page for details.

Invisibly, an object of class `network`

; these functions modify their argument in place.

Carter T. Butts buttsc@uci.edu and David Hunter dhunter@stat.psu.edu

Butts, C. T. (2008). “network: a Package for Managing Relational Data in R.” *Journal of Statistical Software*, 24(2). http://www.jstatsoft.org/v24/i02/

`loading.attributes`

, `network`

, `network.initialize`

, `add.edges`

, `network.extraction`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | ```
#Create an arbitrary adjacency matrix
m<-matrix(rbinom(25,1,0.5),5,5)
diag(m)<-0
g<-network.initialize(5) #Initialize the network
network.adjacency(m,g) #Import the edge data
#Do the same thing, using replacement operators
g<-network.initialize(5)
g[,]<-m
# load edges from a data.frame via network.edgelist
edata <-data.frame(
tails=c(1,2,3),
heads=c(2,3,1),
love=c('yes','no','maybe'),
hate=c(3,-5,2),
stringsAsFactors=FALSE
)
g<-network.edgelist(edata,network.initialize(4),ignore.eval=FALSE)
as.sociomatrix(g,attrname='hate')
g%e%'love'
# load edges from an incidence matrix
inci<-matrix(c(1,1,0,0, 0,1,1,0, 1,0,1,0),ncol=3,byrow=FALSE)
inci
g<-network.incidence(inci,network.initialize(4,directed=FALSE))
as.matrix(g)
# load in biparite dataframe with weights
bipMat<-data.frame(
event1=c(1,2,1,0),
event2=c(0,0,3,0),
event3=c(1,1,0,4),
row.names=c("a","b","c","d"))
net<-network(bipMat,matrix.type='bipartite',ignore.eval=FALSE,names.eval='pies')
as.matrix(net,attername='pies')
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

All documentation is copyright its authors; we didn't write any of that.