R/FindIdsOfConnectedNodesInSubgraph.r

Defines functions FindIdsOfConnectedNodesInSubgraph

Documented in FindIdsOfConnectedNodesInSubgraph

#' @title find Ids of connected nodes in subgraph
#' @description
#' Adds the IDs of the connected nodes in a subgraph to an existing list. 
#' Given the IDs of connected nodes in the full network, this function will find
#' the corresponding IDs in the subgraph
#' 

#' @param idsOfConnectedNodes a list of connected nodes in the full graph
#' @param subgraphOfConnectedNodes a subgraph 
#' @return a list of connected nodes in the subgraph

FindIdsOfConnectedNodesInSubgraph <- function(idsOfConnectedNodes, subgraphOfConnectedNodes) {
    
    
    numConnectedNodes <- length(idsOfConnectedNodes)
    idsOfConnectedNodesInSubgraph <- array(0, length(idsOfConnectedNodes))
    ids <- igraph::V(subgraphOfConnectedNodes)$ID
    
    for (i in 1:numConnectedNodes) {
        idsOfConnectedNodesInSubgraph[i] <- which(ids == idsOfConnectedNodes[i])
    }
    
    return(idsOfConnectedNodesInSubgraph)
} 

Try the CausalR package in your browser

Any scripts or data that you put into this service are public.

CausalR documentation built on Nov. 8, 2020, 5:25 p.m.