You can try the code below
glst <- lapply(
with(df, split(as.character(userid), postid)),
function(x) graph_from_data_frame(t(combn(x, 2)), directed = FALSE)
)
or
lapply(
with(df, split(as.character(userid), postid)),
function(x) simplify(graph_from_data_frame(expand.grid(x, x), directed = FALSE))
)
which produces a list of graph ojbects
$`1`
IGRAPH 125b424 UN-- 2 1 --
+ attr: name (v/c)
+ edge from 125b424 (vertex names):
[1] 1--2
$`2`
IGRAPH 125bde9 UN-- 2 1 --
+ attr: name (v/c)
+ edge from 125bde9 (vertex names):
[1] 1--4
$`3`
IGRAPH 125bde9 UN-- 3 3 --
+ attr: name (v/c)
+ edges from 125bde9 (vertex names):
[1] 2--4 2--5 4--5
If you want to aggregate all sub-graphs, you can use graph.union
> (g <- do.call(graph.union, glst))
IGRAPH 7c8e074 UN-- 4 5 --
+ attr: name (v/c)
+ edges from 7c8e074 (vertex names):
[1] 4--5 2--5 2--4 1--4 1--2

Data
> dput(df)
structure(list(postid = c(3L, 3L, 3L, 1L, 1L, 2L, 2L), userid = c(2L,
4L, 5L, 1L, 2L, 1L, 4L)), class = "data.frame", row.names = c(NA,
-7L))