0
$\begingroup$

What are the source and target functions in igraph package in R? so that source(s->t) = s and target(s->t) = t

I am working on this directed graph example:

require(igraph, quietly=TRUE)
bsk <-read.table("http://www.dimiter.eu/Data_files/edgesdata3.txt", sep='\t', dec=',', header=T)

bsk.network <- graph.data.frame(bsk, directed=T) 

edit: I am trying to write a function like this:

f_source <- function(str,network){
 result <- head_of(network, E(network)[str]); 
}

f_source(AA%->%DD,bsk.network)

The problem is the string. It includes quotations while E(network)[str] does not work with quotations.

$\endgroup$
1
  • $\begingroup$ The problem is what string? I don't see any strings except the file name. Create a test graph dataset we can all use and give an example and show the error message. $\endgroup$
    – Spacedman
    Feb 11, 2016 at 22:40

1 Answer 1

1
$\begingroup$

Given

library(igraph)
set.seed(1)
g <- sample_pa(5)

you got

ends(g, E(g))
#      [,1] [,2]
# [1,]    2    1
# [2,]    3    1
# [3,]    4    1
# [4,]    5    2

and

head_of(g, E(g))
# + 4/5 vertices:
# [1] 2 3 4 5

tail_of(g, E(g))
# + 4/5 vertices:
# [1] 1 1 1 2

source() is an important base function.

$\endgroup$
3
  • $\begingroup$ I edited my question. please take a look. $\endgroup$
    – Hamideh
    Feb 11, 2016 at 18:21
  • 1
    $\begingroup$ I don't understand what you need from the edit. You can query edges like this: E(g)[from("2") & to("1")]. Please add a full reproducible example with a sample graph, your function and the reason, why the output of the function is not what you want. $\endgroup$
    – lukeA
    Feb 11, 2016 at 19:36
  • $\begingroup$ I need two functions called f_source and f_target in my code and I want to subset on specific edges. How can I do that? $\endgroup$
    – Hamideh
    Feb 12, 2016 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.