Build node table from edges

Share:

Description

Get nodes from a data.frame of edges as typically returned by getEdges

Usage

1
getNodes(edges, source = "source", target = "target", ...)

Arguments

edges

data.frame of edges as typically returned by getEdges

source

Column of source nodes in edges, must be a character string, defaults to source.

target

Column of target nodes in edges, must be a character string, required.

...

Any other columns to be passed on to the source nodes - will not be applied to target nodes.

Details

One must keep in mind that nodes need to be unique therefore duplicate values (...) are dropped. Also, the meta-data (...), only applies to the source of edges; NAs are generated for target nodes.

Author(s)

John Coene jcoenep@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# simulate dataset
tweets <- data.frame(text = c("I tweet @you about @him", 
                              "I tweet @me about @you"),
                     screenName = c("me", "him"),
                     favorited = c(TRUE, FALSE),
                     stringsAsFactors = FALSE)

# get edges
edges <- getEdges(data = tweets, tweets = "text", source = "screenName", 
                  str.length = NULL, "favorited")

# get nodes
nodes <- getNodes(edges, source = "source", target = "target", 
                  "favorited")

# plot
g <- igraph::graph.data.frame(edges, directed = TRUE, vertices = nodes)
plot(g, vertex.color = igraph::V(g)$favorited)