[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Neighors with apply
From: |
Gábor Csárdi |
Subject: |
Re: [igraph] Neighors with apply |
Date: |
Wed, 8 Feb 2012 09:17:13 -0500 |
On Wed, Feb 8, 2012 at 8:45 AM, Thomas <address@hidden> wrote:
> I have a vector with a list of nodes, which does have NAs in it although
> they are always at the end of the list, and I'd like to get a list of all
> the neighbors of those nodes:
>
> dlist <- c(100, 101, 105, NA, NA)
>
> neighbors(g, 100)
> neighbors(g, 101)
> neighbors(g, 105)
>
> is there any way to do this using an apply function? Something like:
>
> sapply(dlist, function(neighbors) neighbors(g,))
> or
> lapply(dlist, neighbors, g)
You can do something like this:
g <- graph.ring(10)
dlist <- c(1,2,3,NA,NA)
lapply(na.omit(dlist), neighbors, graph=g)
lapply(dlist, function(v) if (is.na(v)) NA else neighbors(g, v))
The first version drops the NAs before the neighbors() calls, the
second results NAs for them.
Best,
Gabor
>
> Thank you!
>
> Thomas
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help
--
Gabor Csardi <address@hidden> MTA KFKI RMKI