# Set a seed
suppressWarnings(RNGversion("3.5.0"))
set.seed(23)
# Create a simple graph
graph <-
create_graph() %>%
add_n_nodes(n = 5) %>%
add_edges_w_string(
edges = "1->2 1->3 2->4 2->5 3->5")
# Create a data frame with node ID values
# representing the graph edges (with `from` and `to`
# columns), and, a set of numeric values
df <-
data.frame(
from = c(1, 1, 2, 2, 3),
to = c(2, 3, 4, 5, 5),
values = rnorm(5, 5))
# Join the values in the data frame to the
# graph's edges; this works as a left join using
# identically-named columns in the graph and the df
# (in this case `from` and `to` are common to both)
graph <-
graph %>%
join_edge_attrs(
df = df)
# Get the graph's internal edf to show that the
# join has been made
graph %>% get_edge_df()
Run the code above in your browser using DataLab