从 R 中取出结果

Take results out of R

我运行以下代码:

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 objets 没有相同数量的节点。

我找到了解决问题第一部分的方法。

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)))
}