These functions allow users to add nodes attributes:

  • add_node_attribute() offers an {igraph}-style way to add a vector of values to a network as a nodal attribute.

  • mutate_nodes() offers a {tidyverse}-style way to add one or more vectors of values to a network as nodal attributes.

  • rename_nodes() offers a {tidyverse}-style way to rename nodal attributes.

  • select_nodes() offers a {tidyverse}-style way to select a subset of nodal attributes.

  • join_nodes() merges all nodal attributes from one network to another.

Note that while add_*() functions operate similarly as comparable {igraph} functions, mutate*(), bind*(), etc work like {tidyverse} or {dplyr}-style functions.

add_node_attribute(.data, attr_name, vector)

mutate(.data, ...)

mutate_nodes(.data, ...)

rename_nodes(.data, ...)

select_nodes(.data, ...)

join_nodes(
  .data,
  object2,
  .by = NULL,
  join_type = c("full", "left", "right", "inner")
)

bind_node_attributes(.data, object2)

Arguments

.data

An object of a {manynet}-consistent class:

  • adjacency or incidence matrix from {base} R

  • edgelist data.frame from {base} R or tbl/tbl_df from {tibble}

  • stocnet stocnet, from the {manynet} package

  • igraph igraph, from the {igraph} package

  • network network, from the {network} package

  • tidygraph tbl_graph, from the {tidygraph} package

attr_name

Character string naming a nodal attribute. The attribute itself may be a logical mark, numeric measure, or character membership vector.

vector

A vector of values for the new attribute.

...

Additional parameters and arguments passed on internally.

object2

A second object to copy nodes or ties from.

.by

An attribute name to join objects by. By default, NULL.

join_type

A type of join to be used. Options are "full","left", "right", "inner".

Value

A data object of the same class as the function was given.

Details

Not all functions have methods available for all object classes. Below are the currently implemented S3 methods for these functions:

                   data.frame default igraph network stocnet tbl_graph
add_node_attribute                  *      *       *                 *
join_nodes                          *      *               *
mutate_nodes                        *      *       *       *         *
select_nodes                *       *      *               *         *

If a method is not available for a particular class, but a default method is, the default method will attempt to coerce the object to a class for which a method is defined, and then coerce the output back to the original class. If no method is available for any class, an error will be thrown.

Examples

  other <- create_filled(4) |> mutate(name = c("A", "B", "C", "D"))
  add_nodes(other, 4, list(name = c("Matthew", "Mark", "Luke", "Tim")))
#> 
#> ── # Filled network ────────────────────────────────────────────────────────────
#> # A labelled, undirected network of 8 nodes and 6 ties
#> 
#> ── Nodes 
#> # A tibble: 8 × 1
#>   name   
#>   <chr>  
#> 1 A      
#> 2 B      
#> 3 C      
#> 4 D      
#> 5 Matthew
#> 6 Mark   
#> # ℹ 2 more rows
#> 
#> ── Ties 
#> # A tibble: 6 × 2
#>    from    to
#>   <int> <int>
#> 1     1     2
#> 2     1     3
#> 3     1     4
#> 4     2     3
#> 5     2     4
#> 6     3     4
#> 
  other <- create_filled(4) |> mutate(name = c("A", "B", "C", "D"))
  another <- create_filled(3) |> mutate(name = c("E", "F", "G"))
  join_nodes(another, other)
#> ── # Filled network ────────────────────────────────────────────────────────────
#> # A labelled, undirected network of 7 nodes and 3 ties
#> 
#> ── Nodes 
#> # A tibble: 7 × 1
#>   name 
#>   <chr>
#> 1 E    
#> 2 F    
#> 3 G    
#> 4 A    
#> 5 B    
#> 6 C    
#> # ℹ 1 more row
#> 
#> ── Ties 
#> # A tibble: 3 × 2
#>    from    to
#>   <int> <int>
#> 1     1     2
#> 2     1     3
#> 3     2     3
#>