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, ...)
network; these functions modify their argument in place.
networkand a matrix as input, and modifies the supplied
networkobject by adding the appropriate edges.
xto be an adjacency matrix;
xto be an edgelist matrix; and
xto be an incidence matrix.
xto 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
edge.checkargument can be added via
...and will be passed to
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.
#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')