Last data update: 2014.03.03

R: Return the neighborhood set of given vertices
neighborhoodR Documentation

Return the neighborhood set of given vertices

Description

The function returns the neighborhood set of given vertices in the form of list. Optionally user can choose to include the given vertices in the list, too.

Usage

neighborhood(graph, index, return.self = FALSE)

Arguments

graph

An object of graphNEL

index

Names of nodes, whose neighborhood set should be returned

return.self

logical, should the vertex itself also be returned?

Details

Let v be a vertex in a (di)graph, the out-neighborhood or successor set (N+(v), x belongs to V(G) and v->x) and the in-neighborhood or predecessor set (N-(v), x belongs to V(G) and x->v) are jointly returned.

The returned list is indexed by the given node indices, NULL is returned in case of non-existing node.

The nodes are unique, that is, duplicated nodes are removed in results.

Value

A list indexed by the given node indices, each entry containing the neighborhood set of that node (or furthermore including that node).

Author(s)

Jitao David Zhang <jitao_david.zhang@roche.com>

References

D.B. West. Introduction to Graph Theory, Second Edition. Prentice Hall, 2001

Examples

  V <- c("Hamburg","Stuttgart","Berlin","Paris","Bremen")
  E <- list("Hamburg"=c("Berlin","Bremen"),
            "Stuttgart"=c("Berlin","Paris"),
            "Berlin"=c("Stuttgart","Bremen"),
            "Paris"=c("Stuttgart"),
            "Bremen"=c("Hamburg","Berlin"))
  g <- new("graphNEL", nodes=V, edgeL=E, edgemode="directed")
  if(require(Rgraphviz) & interactive()) {
    plot(g, "neato")
  }

  ## simple uses
  neighborhood(g, "Hamburg")
  neighborhood(g, c("Hamburg", "Berlin","Paris"))

  ## in case of non-existing nodes
  neighborhood(g, c("Stuttgart","Ulm"))

  ## also applicable to non-directed graphs
  neighborhood(ugraph(g), c("Stuttgart","Berlin"))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(KEGGgraph)

Attaching package: 'KEGGgraph'

The following object is masked from 'package:graphics':

    plot

> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/KEGGgraph/neighborhood.Rd_%03d_medium.png", width=480, height=480)
> ### Name: neighborhood
> ### Title: Return the neighborhood set of given vertices
> ### Aliases: neighborhood
> 
> ### ** Examples
> 
>   V <- c("Hamburg","Stuttgart","Berlin","Paris","Bremen")
>   E <- list("Hamburg"=c("Berlin","Bremen"),
+             "Stuttgart"=c("Berlin","Paris"),
+             "Berlin"=c("Stuttgart","Bremen"),
+             "Paris"=c("Stuttgart"),
+             "Bremen"=c("Hamburg","Berlin"))
>   g <- new("graphNEL", nodes=V, edgeL=E, edgemode="directed")
> #  if(require(Rgraphviz) & interactive()) {
>     plot(g, "neato")

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

> #  }
> 
>   ## simple uses
>   neighborhood(g, "Hamburg")
$Hamburg
[1] "Berlin" "Bremen"

>   neighborhood(g, c("Hamburg", "Berlin","Paris"))
$Hamburg
[1] "Berlin" "Bremen"

$Berlin
[1] "Stuttgart" "Bremen"    "Hamburg"  

$Paris
[1] "Stuttgart"

> 
>   ## in case of non-existing nodes
>   neighborhood(g, c("Stuttgart","Ulm"))
$Stuttgart
[1] "Berlin" "Paris" 

$Ulm
NULL

> 
>   ## also applicable to non-directed graphs
>   neighborhood(ugraph(g), c("Stuttgart","Berlin"))
$Stuttgart
[1] "Berlin" "Paris" 

$Berlin
[1] "Hamburg"   "Stuttgart" "Bremen"   

> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>