สร้างกราฟสำหรับผู้ใช้ประเภทต่าง ๆ
มาเปรียบเทียบกราฟระหว่างผู้ใช้ที่สมัครสมาชิก Divvy Bike กับลูกค้าทั่วไปที่ไม่ได้สมัครสมาชิกกัน
วิธีที่สะดวกคือใช้ 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()