Learn R Programming

networkR (version 0.1.2)

adjacency: Create adjacency matrix

Description

Create an adjacency matrix from a set of nodes and edges.

Usage

adjacency(from, to, weight = 1, directed = TRUE)

Arguments

from

a vector of nodes where the edges originate

to

a vector of nodes where the edges point to

weight

a numeric vector of weights

directed

logical. Are the edges directed (TRUE, the default) or bidirected(FALSE).

Value

Returns a sparse adjacency matrix

Examples

Run this code
# NOT RUN {
from <- c("A", "A", "A", "B", "C")
to <- c("B", "C", "D", "D", "E")
adjacency(from, to)

from <- c("A", "A", "A", "B", "C")
to <- c("B", "C", "D", "D", "E")
weights <- c(1, .5, 1, .7, 1)
adjacency(from, to, weights)

# }

Run the code above in your browser using DataLab