图同构:全局访问局部变量

时间:2015-07-10 07:48:13

标签: r

我想在循环外打印最终答案R.而且我也只想访问那些同构的图形对象。任何人都可以帮忙吗?

g1 <- graph.ring(10 , directed = FALSE)
g2 <- graph.ring(5 , directed = FALSE)
g3 <- graph.ring(7 , directed = FALSE)
g4 <- graph.ring(6 , directed = FALSE)
g5 <- graph.ring(8 , directed = FALSE)

g <- list(g1,g2,g3,g4,g5)
g 


iso = function(g,i,j)
{ 

   r <- graph.isomorphic(g[[i]],g[[j]])
   return(r)
   print(g[[i]])
   print(g[[j]])

}

for(i in 1:5)
{
  for(j in 1:5)
   {
      r= iso(g , i , j)
      print(r)
      print(g[[i]])
      print(g[[j]])
  }

}

1 个答案:

答案 0 :(得分:0)

您的问题不是很清楚,但我会尝试回答这一部分:

  

我想在循环外打印最终答案。

您要做的是在循环的父框架中设置变量。这可以使用<<-运算符完成:

r <<- iso(g , i , j)

然后在循环之后你可以调用:

print(r)