Skip to contents

From an edge list, identifies isolated nodes (nodes that do not participate in any complete edge, i.e., a row where both from and to are non-NA). It can return only connected nodes (degree > 0) or the full vertex universe (all unique non-NA URLs from both columns, including those from partial/incomplete rows).

Usage

drop_isolates(
  edge_list_df,
  drop = FALSE,
  from_col = "from",
  to_col = "to",
  node_col_name = "node_name"
)

Arguments

edge_list_df

A data frame representing the edge list, typically with columns "from" and "to" (or as specified by `from_col`, `to_col`). Rows where both columns are non-NA represent edges. Rows where one column is NA represent known nodes that do not participate in a complete edge (potential isolates).

drop

Logical. If `TRUE`, returns a single-column data frame containing only node names that participate in at least one complete edge (both from and to are non-NA in the same row). If `FALSE` (default), returns a single-column data frame of all unique non-NA node names present in either column of `edge_list_df` (the full vertex universe, including isolates).

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".

node_col_name

Name for the output column containing node names. Default "node_name". When used with [compute_pagerank()], this should match its `vertex_col_name` parameter.

Value

A single-column data frame named according to `node_col_name`. If `drop = TRUE`, contains unique node names with degree > 0 (from complete edges only). If `drop = FALSE`, contains all unique non-NA node names from both columns of the input edge list (full vertex universe). Returns an empty data frame with the correct column name if no nodes meet the criteria or if the input edge list is empty/all NAs.

Examples

# Edge list with partial rows
# (NA in one column = known node, not a complete edge)
edges <- data.frame(
  from = c("A", "B", "C", NA, "D"),
  to = c("B", "C", "A", "E", NA)
)
# Complete edges: A->B, B->C, C->A.
# Partial rows: NA->E (E is isolate), D->NA (D is isolate).

# Get only nodes participating in complete edges (A, B, C)
active_nodes <- drop_isolates(edges, drop = TRUE)
print(active_nodes)
#>   node_name
#> 1         A
#> 2         B
#> 3         C

# Get all unique nodes including isolates from partial rows (A, B, C, D, E)
all_nodes <- drop_isolates(edges, drop = FALSE)
print(all_nodes)
#>   node_name
#> 1         A
#> 2         B
#> 3         C
#> 4         D
#> 5         E

# Edge list with no isolates (all rows are complete edges)
edges_complete <- data.frame(
  from = c("X", "Y"),
  to = c("Y", "X")
)
drop_isolates(edges_complete, drop = TRUE) # X, Y
#>   node_name
#> 1         X
#> 2         Y
drop_isolates(edges_complete, drop = FALSE) # X, Y (same, no partial rows)
#>   node_name
#> 1         X
#> 2         Y

# Empty edge list
empty_edges <- data.frame(
  from = character(0), to = character(0)
)
drop_isolates(empty_edges, drop = TRUE)
#> [1] node_name
#> <0 rows> (or 0-length row.names)
drop_isolates(empty_edges, drop = FALSE)
#> [1] node_name
#> <0 rows> (or 0-length row.names)

# Edge list with only NAs
na_edges <- data.frame(
  from = NA_character_, to = NA_character_
)
drop_isolates(na_edges, drop = TRUE)
#> [1] node_name
#> <0 rows> (or 0-length row.names)
drop_isolates(na_edges, drop = FALSE)
#> [1] node_name
#> <0 rows> (or 0-length row.names)

# Custom column names
custom_edges <- data.frame(
  source = c("S1"), target = c("T1")
)
drop_isolates(
  custom_edges,
  from_col = "source", to_col = "target", node_col_name = "vertex"
)
#>   vertex
#> 1     S1
#> 2     T1