Skip to content

Instantly share code, notes, and snippets.

@jinhangjiang
Created June 24, 2021 09:04
Show Gist options
  • Save jinhangjiang/8e198d7d7b58182441afc945c9874b41 to your computer and use it in GitHub Desktop.
Save jinhangjiang/8e198d7d7b58182441afc945c9874b41 to your computer and use it in GitHub Desktop.
igraph label vertices
## Adjacency list
adjlist <- get.adjlist(g)
adjlist[1]
# $Adam
# + 3/8 vertices, named, from 50df64b:
# [1] Judy Bobby Sam
## Edge list
as.data.frame(get.edgelist(g))
# V1 V2
# 1 Adam Judy
# 2 Adam Bobby
# ... ...
# 13 Jay Tom
# 14 Jay Jerry
## Adjacency matrix
# alternatively "as_adjacency_matrix(g)"
get.adjacency(g)
# 8 x 8 sparse Matrix of class "dgCMatrix"
# Adam Judy Bobby Sam Frank Jay Tom Jerry
# Adam . 1 1 1 . . . .
# Judy 1 . 1 . 1 . . .
# Bobby 1 1 . . 1 1 . .
# Sam 1 . . . 1 . 1 1
# Frank . 1 1 1 . 1 1 .
# Jay . . 1 . 1 . 1 1
# Tom . . . 1 1 1 . .
# Jerry . . . 1 . 1 . .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment