In this exercise, we will learn how to add attributes to the edges of a network using the statnet package in R. Edge attributes can provide additional information about the relationships in a network, such as their strength, type, or weight.
Suppose we have the network adjacency_network
and we want to assign a random value to each edge in the network.
We can add this information as an edge attribute using the set.edge.attribute()
function:
network::set.edge.attribute(adjacency_network, "rndval", runif(network.edgecount(adjacency_network), 0, 1))
The network::
prefix is used to specify that the function is from the network package.
We can inspect the values of an edge attribute using the %e%
operator:
adjacency_network %e% "rndval"
[1] 0.6122244 0.3373301 0.2120034 0.8008051 0.5045893 0.4359113
This will return a vector of the random values assigned to each edge.
We can get a summary of the edge attribute values using the summary()
function:
summary(adjacency_network %e% "rndval")
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.2120 0.3620 0.4703 0.4838 0.5853 0.8008
This will return statistical measures such as the minimum, maximum, and mean of the attribute values.
Create a vector as edge attribute times_texted
.
This vector contains frequency of which the friends interacted with each other.
friends_network
from the previous exercise.
You can look at the edgelist to see which order the edges are in with
the as.edgelist(friends_network)
function.
Assume that:
friends_network
, as created before, has been loaded.