从R中取结果

时间:2015-07-14 07:53:43

标签: r dataframe export igraph

我运行以下代码:

filenames <- list.files(path=getwd(),pattern="fullmat+.*dta")
list(filenames)

names <-substr(filenames,1,12)
specific <-substr(filenames,8,12)

for(i in names) 
{
  filepath <- file.path("D:/Educacion/PeerEffects/matriz de contactos/Intentos",paste(i,".dta",sep=""))
  assign(i, read.dta13(filepath))
}

for (i in specific){
  assign(paste0("A", i), unname(as.matrix(get(paste0("fullmat", i)))))
  assign(paste0("B", i), graph.adjacency(get(paste0("A", i)), mode = "directed", weighted = NULL, diag = FALSE))
}

现在我运行以下计算:

##Calculate descriptive statistics from the igraphs (part 1)
for (i in specific)  {
  m <- get(paste0('B', i)) 
  assign(paste0("diameter", i), diameter(m))
  assign(paste0("APL", i), average.path.length(m))
  assign(paste0("transitivity", i), transitivity(m))
  }

##Calculate descriptive statistics from the igraphs (part 2)
for (i in specific)  {
  m <- get(paste0('B', i)) 
  assign(paste0("degree", i), degree(m))
  assign(paste0("close", i), closeness(m))
  assign(paste0("betw", i), betweenness(m))
  assign(paste0("edbetw", i), edge.betweenness(m))
}

我需要的是将所有计算放在一起并将它们带到stata。请注意,在第2部分中,值位于节点级别,并且所有igraph目标都没有相同数量的节点。

1 个答案:

答案 0 :(得分:0)

我找到了如何解决问题的第一部分。

graphdata = data.frame()
for (i in specific)  {
graphdata[i, 1] = data.frame(get(paste0('diameter', i)))
graphdata[i, 2] = data.frame(get(paste0('APL', i)))
graphdata[i, 3] = data.frame(get(paste0('transitivity', i)))
}