I think you want the adjacency matrix from gmG
library(graph)
#> Loading required package: BiocGenerics
#>
#> Attaching package: 'BiocGenerics'
#> The following objects are masked from 'package:stats':
#>
#> IQR, mad, sd, var, xtabs
#> The following objects are masked from 'package:base':
#>
#> anyDuplicated, aperm, append, as.data.frame, basename, cbind,
#> colnames, dirname, do.call, duplicated, eval, evalq, Filter, Find,
#> get, grep, grepl, intersect, is.unsorted, lapply, Map, mapply,
#> match, mget, order, paste, pmax, pmax.int, pmin, pmin.int,
#> Position, rank, rbind, Reduce, rownames, sapply, setdiff, sort,
#> table, tapply, union, unique, unsplit, which.max, which.min
library(igraph)
#>
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:graph':
#>
#> degree, edges, intersection, union
#> The following objects are masked from 'package:BiocGenerics':
#>
#> normalize, path, union
#> The following objects are masked from 'package:stats':
#>
#> decompose, spectrum
#> The following object is masked from 'package:base':
#>
#> union
library(pcalg)
data(gmG)
g <- gmG$g
ig <- igraph.from.graphNEL(g)
sparse_matrix <- as_adjacency_matrix(ig)
adjacency_matrix <- as.matrix(sparse_matrix)
adjacency_matrix
#> Author Bar Ctrl Goal V5 V6 V7 V8
#> Author 0 1 0 0 0 1 0 1
#> Bar 0 0 1 0 1 0 0 0
#> Ctrl 0 0 0 0 0 0 0 0
#> Goal 0 0 0 0 0 0 0 0
#> V5 0 0 0 0 0 1 0 1
#> V6 0 0 0 0 0 0 1 0
#> V7 0 0 0 0 0 0 0 0
#> V8 0 0 0 0 0 0 0 0
Created on 2023-09-01 with reprex v2.0.2