A more useful usage statement than the above (but prohibited by R's overzealous documentation restrictions from appearing there) is as follows:
x + y
x - y
x * y
x %c% y!x
x | y
x & y
"+"(x, y, attrname=NULL)
"-"(x, y, attrname=NULL)
"*"(x, y, attrname=NULL)
In general, the binary network operators currently function by converting their arguments to adjacency matrices, carrying out the specified operation on those matrices, and then returning the result in network form. This is rather inefficient, and results in the loss of other attributes; such poor behavior is not guaranteed to be maintained in future versions of the network
package.
Apart from the above, the specific operations carried out by these operators are mostly self-explanatory. One exception to this is x %c% y
, which returns the network formed from the composition of graphs x
and y
(respectively). (Note that this may contain loops, whether or not the original networks allowed them.) Certain operators also support an attrname
argument when called explicitly, which allows the user to specify an edge attribute to use when extracting the adjacency matrices. If such an argument is given, the resulting edge values are returned via an attribute of the same name in the newly constructed graph.
Slightly different behavior is exhibited by the unary operator, !
, which returns the complement of its argument. The graph which is returned contains all attributes of the original, save for edge attributes (as none of the original edges are retained). Note that the complement of a large, sparse graph has many edges, with concomitant memory consumption. When working with such graphs, consider whether some other mechanism (e.g., adjacency checking on the original graph) might prove more efficient.