Learn R Programming

migraph (version 0.12.1)

add: Adding and copying attributes from one graph to another

Description

These functions allow users to add attributes to a graph from another graph or from a specified vector supplied by the user.

Usage

add_node_attribute(object, attr_name, vector)

add_tie_attribute(object, attr_name, vector)

copy_node_attributes(object, object2)

join_ties(object, object2, attr_name)

Arguments

object

An object of a migraph-consistent class:

  • matrix (adjacency or incidence) from {base} R

  • edgelist, a data frame from {base} R or tibble from {tibble}

  • igraph, from the {igraph} package

  • network, from the {network} package

  • tbl_graph, from the {tidygraph} package

attr_name

Name of the new attribute in the resulting object.

vector

A vector of values for the new attribute.

object2

A second object to copy nodes or edges from.

Functions

  • add_node_attribute(): Insert specified values from a vector into the graph as node attributes

  • add_tie_attribute(): Insert specified values from a vector into the graph as tie attributes

  • copy_node_attributes(): Copies node attributes from a given graph into specified graph

  • join_ties(): Copies ties from another graph to specified graph and adds a tie attribute identifying the ties that were newly added

See Also

Other manipulations: as(), grab, reformat, transform()

Examples

Run this code
add_node_attribute(mpn_elite_mex, "wealth", 1:35)
add_node_attribute(mpn_elite_usa_advice, "wealth", 1:14)
add_tie_attribute(ison_adolescents, "weight", c(1,2,1,1,1,3,2,2,3,1))
autographr(mpn_elite_mex)
both <- join_ties(mpn_elite_mex, generate_random(mpn_elite_mex), "random")
autographr(both)
random <- to_uniplex(both, "random")
autographr(random)
autographr(to_uniplex(both, "orig"))

Run the code above in your browser using DataLab