Exercise

Extracting types of edges

In this exercise, you will match the customer IDs in the customer dataframe with the customer edgelist to find out whether each edge is a churn, non-churn or a mixed edge. Using the function match(), you will add two columns to the edgelist.

  1. fromLabel with the churn status of the from column
  2. toLabel with the churn status of the to column

The command match(x, y) returns a vector with the location of x in y. In the figure above match(edgeList$from, customers$id) is 1,1,1,2,2. For example, the fourth line in edgeList$from, which is customer with id 393, is the second element in customers$id. The churn label of this customer is, therefore, customers[2,2] or 0. Similarly, the churn label of everyone in edgeList$from is customers[match(edgeList$from, customers$id),2].

Instructions

100 XP
  • Add a column called FromLabel to the edgeList dataframe with the label of the from nodes by matching customers$id with edgeList$from and extracting customers$churn.
  • Do the same for the to edges, and call this column ToLabel.
  • Add a column called edgeType to the edgeList dataframe that is the sum of the columns FromLabel and ToLabel.
  • Use the table() function to see the number of each type of edge.