Question about Assessing Small World Properties

Hi everyone, I am engaged in a community research and I am trying to learn igraph package. I mainly use the book Statistical Analysis of Network Data with R for reference and it does help a lot. However I was caught up in a question about assessing Small World properties. I followed the code in the book and everything was fine at first, but when I adjusted the data frame to “mode=mutual”, all the outcome of clust.coef.dir turned to Inf or NaN .

So I made up a small network (as attached):


and I tried again, but the outcome was still Inf. Here is my code:

>data <- read.table("try.csv", header=TRUE, sep=",")
library(igraph)
g0 <- graph_from_data_frame(data[,1:2], directed=TRUE)
g1 <- as.undirected(g0, mode='mutual')
#Small World Test
clust.coef.dir <- function(graph) {
  A <- as.matrix(get.adjacency(graph))
  S <- A + t(A)
  deg <- degree(graph, mode=c("total"))
  num <- diag(S %*% S %*% S)
  denom <- diag(A %*% A)
  denom <- 2 * (deg * (deg - 1) - 2 * denom)
  cl <- mean(num / denom)
  return(cl)
}
>ntrials <- 1000
nv <- vcount(g1)
ne <- ecount(g1)
cl.rg <- numeric(ntrials)
apl.rg <- numeric(ntrials)
for (i in (ntrials)) {
  g.rg <-erdos.renyi.game(nv, ne, type="gnm", directed=FALSE)
  cl.rg[i] <- clust.coef.dir(g.rg)
  apl.rg[i] <- average.path.length(g.rg)
}
>summary(cl.rg)
summary(apl.rg)
>clust.coef.dir(g1)
average.path.length(g1)

and my result shows:

> summary(cl.rg)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
      0       0       0       0       0       0       1 
> summary(apl.rg)
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
0.000000 0.000000 0.000000 0.002067 0.000000 2.066667 
> 
> clust.coef.dir(g1)
[1] Inf
> average.path.length(g1)
[1] 1.933333

I am really troubled by the result. I sincerely hope that somebody could help me with this. Thanks!