Skip to contents

Rename Nodes

Usage

rename_nodes(x, from, to = NULL, keep_format = FALSE, directed = NULL)

Arguments

x

Network input.

from

Character vector of current labels, or a named character vector mapping old label to new (in which case to is not used).

to

Character vector of new labels, the same length as from.

keep_format

Logical. If TRUE, a matrix, igraph, statnet network or tna input is returned in its own format. An edge-list data frame or a qgraph object is returned as a cograph_network with a cograph_no_format_roundtrip warning. Default FALSE returns a cograph_network.

directed

Logical or NULL. Directedness used to read the input. NULL (default) detects it from the input.

Value

A cograph_network with the renamed nodes, or the input format when keep_format = TRUE. Labels not named in from are unchanged. A cograph_bad_selection error is raised when from names a node that is not in the network or when the renaming would give two nodes the same label.

Examples

rename_nodes(regulation_net, from = "Plan", to = "Planning")
#> Cograph network: 10 nodes, 30 edges ( directed )
#> Source: matrix 
#>   Nodes (10): Explore, Planning, Monitor, Adapt, Reflect, Discuss, ... +4 more
#>   Edges: 30 / 90 (density: 33.3%)
#>   Weights: [0.050, 0.490]  |  mean: 0.265
#>   Strongest edges:
#>     Share -> Monitor  0.490
#>     Planning -> Evaluate  0.490
#>     Evaluate -> Adapt  0.430
#>     Synthesize -> Reflect  0.420
#>     Planning -> Discuss  0.400
#> Layout: none 
#>   Use as.data.frame() for the edge table, as.data.frame(what = "nodes") for the nodes.