Learn R Programming

netdiffuseR (version 1.17.0)

isolated: Find and remove isolated vertices

Description

Find and remove unconnected vertices from the graph.

Usage

isolated(graph, undirected = getOption("diffnet.undirected"))
drop_isolated(graph, undirected = getOption("diffnet.undirected"))

Arguments

graph
Any class of accepted graph format (see netdiffuseR-graphs).
undirected
Logical scalar. When TRUE only the lower triangle will be processed.

Value

When graph is an adjacency matrix:Otherwise, when graph is a list

See Also

Other data management functions: as_diffnet, edgelist_to_adjmat, egonet_attrs, survey_to_diffnet

Examples

Run this code
# Generating random graph
set.seed(123)
adjmat <- rgraph_er()

# Making nodes 1 and 4 isolated
adjmat[c(1,4),] <- 0
adjmat[,c(1,4)] <- 0
adjmat

# Finding isolated nodes
iso <- isolated(adjmat)
iso

# Removing isolated nodes
drop_isolated(adjmat)


# Now with a dynamic graph
graph <- rgraph_er(n=10, t=3)

# Making 1 and 5 isolated
graph <- lapply(graph, "[<-", i=c(1,5), j=1:10, value=0)
graph <- lapply(graph, "[<-", i=1:10, j=c(1,5), value=0)
graph

isolated(graph)
drop_isolated(graph)

Run the code above in your browser using DataLab