In [2]:
library(igraph)


Attaching package: ‘igraph’

The following objects are masked from ‘package:stats’:

    decompose, spectrum

The following object is masked from ‘package:base’:

    union


In [3]:
graph.empty(n=10, directed=TRUE)


IGRAPH D--- 10 0 -- 
+ edges:

In [4]:
graph.star(n=10, mode="out")


IGRAPH D--- 10 9 -- Out-star
+ attr: name (g/c), mode (g/c), center (g/n)
+ edges:
[1] 1-> 2 1-> 3 1-> 4 1-> 5 1-> 6 1-> 7 1-> 8 1-> 9 1->10

In [5]:
graph.ring(n=10)


IGRAPH U--- 10 10 -- Ring graph
+ attr: name (g/c), mutual (g/l), circular (g/l)
+ edges:
 [1] 1-- 2 2-- 3 3-- 4 4-- 5 5-- 6 6-- 7 7-- 8 8-- 9 9--10 1--10

In [8]:
edges <- c(1,2,3,2,2,4)
edges <- c(edges,3,4)
g <- graph(edges, n=max(edges), directed=FALSE)
plot(g)



In [11]:
distances(g,3,1)[[1]]


2

In [34]:
createsquare4NeigboursList <- function(n, m){
    return <- numeric()
    for(i in 1:(n)){
        for(j in 1:(m)){
            current <- ((i-1)*n)+j
            if(j<(m))
                return <- c(return,current,(current+1))
            if(i<(n))
                return <- c(return,current,(current+n))
        } 
    }
    return
}
q <- createsquare4NeigboursList(3,3)
q


  1. 1
  2. 2
  3. 1
  4. 4
  5. 2
  6. 3
  7. 2
  8. 5
  9. 3
  10. 6
  11. 4
  12. 5
  13. 4
  14. 7
  15. 5
  16. 6
  17. 5
  18. 8
  19. 6
  20. 9
  21. 7
  22. 8
  23. 8
  24. 9

In [38]:
edges <- q
g <- graph(edges, n=max(edges), directed=FALSE)
plot(g)



In [36]:
g <- delete_vertices(g, 6)

In [40]:
plot(delete_vertices(g, 6))



In [ ]: