View source: R/get_unique_edges.R
| get_unique_edges | R Documentation |
Removes duplicate edge rows from an edge list data frame and provides control over how self-loops (e.g., a -> a) are handled.
get_unique_edges(
edge_list_df,
self_loops = c("drop", "keep"),
from_col = "from",
to_col = "to"
)
edge_list_df |
A data frame representing the edge list, typically with columns "from" and "to" (or as specified by 'from_col', 'to_col'). |
self_loops |
A character string specifying how to handle self-loops. Must be one of "drop" (default) or "keep". |
from_col |
Name of the source node column in 'edge_list_df'. Default "from". |
to_col |
Name of the target node column in 'edge_list_df'. Default "to". |
Any edge where either from or to is NA is automatically dropped before deduplication and self-loop handling.
A data frame with unique edges, with self-loops handled according to the 'self_loops' argument. The from/to columns are coerced to character; all other columns in the input are preserved (first occurrence kept on dedup). If input columns are factors, they are converted to characters in the output.
edges <- data.frame(
from = c("A", "B", "A", "C", "D"),
to = c("B", "C", "B", "C", "D")
)
get_unique_edges(edges, self_loops = "drop")
get_unique_edges(edges, self_loops = "keep")
# With custom column names
edges_custom <- data.frame(
source = c("X", "Y", "X"),
target = c("Y", "Y", "Y")
)
get_unique_edges(edges_custom, from_col = "source", to_col = "target")
# With NAs (NAs are preserved as they are,
# duplicates involving NAs are also removed)
edges_na <- data.frame(
from = c("A", NA, "A", "B", NA),
to = c("B", "C", "B", "D", "C")
)
get_unique_edges(edges_na, self_loops = "keep")
# No self-loops with NA to drop
get_unique_edges(edges_na, self_loops = "drop")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.