始める無料で始める

ユーザータイプ別にグラフを作る

divvyのサブスク利用者と、登録のないカジュアルな利用者で、グラフを比較してみましょう。

グラフを作る前に dplyr でデータを加工し、graph_from_data_frame() に渡すのが便利です。ここで役立つ dplyr 関数に n() があります。これは、データフレーム内のそのグループの行数を返します。

この演習はコースの一部です

ケーススタディ:R でのネットワーク分析

コースを見る

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

subscribers <- bike_dat %>% 
  # Filter for rows where usertype is Subscriber
  ___(___ == "___")

# Count the number of subscriber trips
n_subscriber_trips <- nrow(___)

subscriber_trip_graph <- subscribers %>% 
  # Group by from_station_id and to_station_id
  ___(___, ___) %>% 
  # Calculate summary statistics
  summarize(
    # Set weights as proportion of total trips
    weights = ___() / n_subscriber_trips
  ) %>%
  # Make a graph from the data frame
  graph_from_dataframe()
コードを編集して実行