Learn R Programming

stCEG (version 0.1.0)

delete_nodes: Delete Nodes from an Event Tree

Description

This function removes specified nodes from an event tree, updating edges to maintain the tree structure while ensuring that node IDs remain sequential.

Usage

delete_nodes(
  event_tree_obj,
  nodes_to_delete,
  level_separation = 1000,
  node_distance = 300
)

Value

A list containing:

  • $eventtree: A visNetwork object representing the updated event tree.

  • $filtereddf: The filtered data frame, returned invisibly.

Arguments

event_tree_obj

A list containing the event tree object, which includes:

  • $eventtree$x: A list with nodes and edges data frames.

  • $filtereddf: The data frame used to create the event tree.

nodes_to_delete

A character vector of node IDs to delete from the event tree.

level_separation

Numeric value specifying the spacing between levels in the hierarchical layout. Default is 1000.

node_distance

Numeric value specifying the distance between nodes in the layout. Default is 300.

Details

The function performs the following steps:

  • Identifies outgoing and incoming edges for each node marked for deletion.

  • Redirects outgoing edges to the sources of the incoming edges.

  • Updates the edges and nodes data frames to reflect the new connections.

  • Ensures node IDs are sequentially re-assigned.

  • Adjusts outgoing edge counts for affected nodes.

  • Removes orphaned nodes (nodes with no connections).

  • Returns an updated visNetwork visualization of the event tree.

Examples

Run this code
data <- homicides
event_tree <- create_event_tree(data, columns = c(1,2,4,5), "both")
event_tree

updated_tree <- delete_nodes(event_tree, nodes_to_delete = c("s14", "s18"))
updated_tree

Run the code above in your browser using DataLab