network_view | R Documentation |
Returns a network with edges optionally filtered according to a specified criterion and with edge attributes optionally computed from other edge attributes.
network_view(x, ..., .clear = FALSE, .sep = ".")
x |
a |
... |
a list of attribute or filtering specifications. See Details. |
.clear |
whether the edge attributes not set by this call should be deleted. |
.sep |
when specifying via a character vector, use this as the separator for concatenating edge values. |
Attribute specification arguments have the form
<newattrname> = <expr>
, where <newattrname>
specifies the
name of the new edge attribute (or attribute to be overwritten)
and <expr>
can be one of the following:
The function will be passed two arguments, the
edgelist tibble
and the network, and must return a vector of
edge attribute values to be set on the edges in the order
specified.
The expression on the RHS of the formula will be
evaluated with names in it referencing the edge attributes. The
input network may be referenced as .nw
. The expression's result
is expected to be a vector of edge attribute values to be set on
the edges in the order specified.
If of length one, the edge attribute with
that name will simply be copied; if greater than one, the attribute
values will be concatenated wtih the .sep
argument as the
separator.
I()
The object will be used directly to set the edge attribute.
Filtering arguments are specified the same way as attribute
arguments, but they must be unnamed arguments (i.e., must be passed
without the =
) and must return a logical or numeric vector
suitable for indexing the edge list. Multiple filtering arguments
may be specified, and the edge will be kept if it satisfies
all. If the conjunction of the edge's original states and the
filtering results is ambiguous (i.e., NA
), it will be set as
missing.
A network
object with modified edges and edge attributes.
data(florentine)
flo <- flomarriage
flo[,,add.edges=TRUE] <- as.matrix(flomarriage) | as.matrix(flobusiness)
flo[,, names.eval="m"] <- as.matrix(flomarriage)==1
flobusiness[3,5] <- NA
flo[,, names.eval="b"] <- as.matrix(flobusiness)==1
flo
(flob <- network_view(flo, "b"))
(flobusiness) # for comparison
(flob <- network_view(flo, ~b&m))
(flobusiness & flomarriage) # for comparison
as.matrix(flob <- network_view(flo, bm=~b+m), attrname="bm")
(as.matrix(flobusiness) + as.matrix(flomarriage)) # for comparison
as.matrix(flob <- network_view(flo, ~b, bm=~b+m), attrname="bm")
as.matrix(flobusiness)*(1+as.matrix(flomarriage)) # for comparison
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.