[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] induced.subgraph in for

From: Chris Watson
Subject: Re: [igraph] induced.subgraph in for
Date: Tue, 28 Jul 2015 14:48:42 -0400

One problem is specifying the index for your "for" loop:
You have "for(i in min(V(net)$PY):max(V(net)$PY)){"

This will then mean "i" will be 1960, 1961, 1962, ..., 2014 (or whatever the minimum and maximum are)
It would probably be better if you used
for (i in seq_len(V(net)$PY)) {
netl[[i]] <- pegar.subgrafo(net, V(net)$PY[i])

You may need to add a "sort(V(net)$PY)" somewhere.
I would remove the final line, where you have the "is.null" function; it may have unintended consequences, so you should try it on a simple example.
You can also probably remove your function "pegar.subgrafo" and include the iterator directly in the loop, calling "induced.subgraph".

On Tue, Jul 28, 2015 at 10:54 AM, Roney Fraga Souza <address@hidden> wrote:
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
# https://dl.dropboxusercontent.com/u/61883020/db.rds
url  <- "https://dl.dropboxusercontent.com/u/61883020/db.rds"
download.file(url, destfile= "./db.rds",method="curl")


db <- readRDS("db.rds")

lapply(db, names)
lapply(db, dim)

net <- graph.data.frame(

# > 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))]

# end code

Thanks for any sugestion.


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

[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

igraph-help mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]