사용자 유형별 그래프 만들기
가입자(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()