|
From: | Roney Fraga Souza |
Subject: | [igraph] induced.subgraph in for |
Date: | Tue, 28 Jul 2015 15:54:00 +0100 |
Hello everyone, I have a network where the papers are nodes and citations are links. To generate a network I do: #------------------------------ # begin code #------------------------------ # Download the data # the file 'db.rds' has 38.6 MB download.file(url, destfile= "./db.rds",method="curl") library(igraph) db <- readRDS("db.rds") lapply(db, names) lapply(db, dim) db[[1]][1:6,c('name','PY')] db[[2]][1:6,] net <- graph.data.frame( db[[2]], directed=TRUE, vertices=db[[1]] ) # > print(net) # IGRAPH DN-- 29168 111039 -- # + attr: name (v/c), PT (v/c), AU (v/c), BA (v/c), BE (v/c), GP # | (v/c), AF (v/c), BF (v/c), CA (v/c), TI (v/c), SO (v/c), SE # | (v/c), BS (v/c), LA (v/c), DT (v/c), CT (v/c), CY (v/c), CL # | (v/c), SP (v/c), HO (v/c), DE (v/c), ID (v/c), AB (v/c), C1 # | (v/c), RP (v/c), EM (v/c), RI (v/c), OI (v/c), FU (v/c), FX # | (v/c), CR (v/c), NR (v/n), TC (v/n), Z9 (v/n), PU (v/c), PI # | (v/c), PA (v/c), SN (v/c), EI (v/c), BN (v/c), J9 (v/c), JI # | (v/c), PD (v/c), PY (v/n), VL (v/c), IS (v/c), PN (v/c), SU # | (v/c), SI (v/c), MA (v/c), BP (v/c), EP (v/c), AR (v/c), DI # | (v/c), D2 (v/c), PG (v/n), WC (v/c), SC (v/c), GA (v/c), UT # | (v/c), PM (v/n) # + edges (vertex names): # Error in seq_len(no) : argument must be coercible to non-negative integer #------------------------------ # end code #------------------------------ I do not know the reason for this message: "Error in seq_len(no) : argument must be coercible to non-negative integer". But this is not the main point (maybe). My network is built by published articles from 1904 until 2014. I would like to create a cumulative network for each year. For example: #------------------------------ # begin code #------------------------------ # V(net)$PY = publication year # net.until.1960 <- induced.subgraph(net, V(net)$PY<=1960) net.until.1970 <- induced.subgraph(net, V(net)$PY<=1970) net.until.1980 <- induced.subgraph(net, V(net)$PY<=1980) net.until.1990 <- induced.subgraph(net, V(net)$PY<=1990) #------------------------------ # end code #------------------------------ But when I run the last code in a loop only the first result is returned. #------------------------------ # begin code #------------------------------ # get network pegar.subgrafo <- function(x,i){induced.subgraph(x, V(x)$PY<=i)} # empty list netl <- list() # generate networks for years for(i in min(V(net)$PY):max(V(net)$PY)){ netl[[i]] <- pegar.subgrafo(net,i) } # delete NULL netl <- netl[ -(which(sapply(netl,is.null), arr.ind=TRUE))] netl #------------------------------ # end code #------------------------------ Thanks for any sugestion. regards, Roney #------------------------------ > sessionInfo() R version 3.2.1 (2015-06-18) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.10.4 (Yosemite) locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] igraph_1.0.1 vimcom_1.2-6 setwidth_1.0-4 colorout_1.1-1 loaded via a namespace (and not attached): [1] magrittr_1.5 tools_3.2.1 #------------------------------ |
[Prev in Thread] | Current Thread | [Next in Thread] |