开始使用免费开始使用

统计不同类型的边

在本练习中,您将使用 edgeList 数据框中的 edgeType 列统计各类边的数量。 在 edgeList$edgeType 列中共有三种取值:

  • 0:连接两个非 churn 节点的边。
  • 1:连接一个非 churn 节点和一个 churn 节点的边。这类边称为混合(mixed)或跨标签(cross-label)边。
  • 2:连接两个 churn 节点的边。

本练习是课程的一部分

使用 R 进行网络数据的预测分析

查看课程

练习说明

  • 通过对 edgeList$edgeType 进行条件筛选,统计 churn 边的数量。将结果赋给 ChurnEdges
  • 通过对 edgeList$edgeType 进行条件筛选,统计非 churn 边的数量。将结果赋给 NonChurnEdges
  • 通过对 edgeList$edgeType 进行条件筛选,统计混合边的数量。将结果赋给 MixedEdges
  • 统计边的总数,并将结果赋给 edges

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Count churn edges
ChurnEdges <- sum(edgeList$edgeType == ___)
 
# Count non-churn edges
NonChurnEdges <- sum(___ == ___)
 
# Count mixed edges
MixedEdges <- ___
 
# Count all edges
___ <- ChurnEdges + NonChurnEdges + MixedEdges

#Print the number of edges
edges
编辑并运行代码