makeVertexAtt: merge data.frame attributes to an igraph (network) object

Description Usage Arguments Value Examples

Description

Enriches an igraph object with node/vertex attributes from a data.frame

Usage

1
makeVertexAtt(g, df, vname, by.df, by.g = "name")

Arguments

g

igraph object to which you want to add a node/vertex attribute

df

data.frame containing the attribute you want to add to igraph

vname

name of column in data.frame df that you will merge into igraph

by.df

unique key in data.frame that you will use to merge attribute into igraph

by.g

unique key in igraph that you will use to merge attribute from data.frame

Value

a vector of attributes that correspond in order with the nodes in your igraph

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
require('igraph')
actors <- data.frame(names=c("Alice", "Bob", "Cecil", "David","Esmeralda"),
age=c(48,33,45,34,21),
gender=c("F","M","F","M","F"))
relations <- data.frame(from=c("Bob", "Cecil", "Cecil", "David",
                              "David", "Esmeralda"),
                       to=c("Alice", "Bob", "Alice", "Alice", "Bob", "Alice"),
                       same.dept=c(FALSE,FALSE,TRUE,FALSE,FALSE,TRUE),
                       friendship=c(4,5,5,2,1,1), advice=c(4,5,5,4,2,3))
g <- igraph::graph.edgelist(as.matrix(relations[,c('from', 'to')]), directed=T)

V(g)$age <- makeVertexAtt(g, df=actors, vname='age', by.df='names', by.g='name')

brooksandrew/Rsenal documentation built on May 13, 2019, 7:50 a.m.