LoslegenKostenlos loslegen

Node attributes and subsetting

In this exercise you will learn how to add attributes to vertices in the network and view them.

Diese Übung ist Teil des Kurses

Network Analysis in R

Kurs anzeigen

Anleitung zur Übung

  • Create a new vertex attribute called 'gender' from the vector genders using set_vertex_attr().
  • Create a new vertex attribute called 'age' from the vector ages using set_vertex_attr().
  • View all vertex attributes using vertex_attr().
  • View the attributes of the first five vertices in a dataframe using V(g)[[]].

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

library(igraph)

# Inspect the objects 'genders' and 'ages'
genders
ages

# Create new vertex attribute called 'gender'
g <- ___(g, "gender", value = genders)

# Create new vertex attribute called 'age'
g <- set_vertex_attr(g, "___", value = ___)

# View all vertex attributes in a list
___(g)

# View attributes of first five vertices in a dataframe
V(___)[[1:5]] 

Code bearbeiten und ausführen