開始使用免費開始

辨識使用者輪廓

我們持續探索推文的資料集。這些元素存放在一個含有 5055 個子列表的巢狀列表中,我們正用 purrr 來探索。

在這個練習中,我們要回答一個關於使用者行為的問題:有多少使用者只做過轉推,從未發布任何「原創內容」?在 Twitter 上常見的經驗法則是,大約有 80% 的人只會轉推,20% 的人會發布內容,這符合帕累托法則(Pareto's law)。我們將在本練習中驗證這點。

為此,我們需要把資料集分成兩部分,接著分別計算使用者總數,以及只在「只轉推」群組中的使用者數量。

purrr 已為你載入,rstudioconf 列表也仍在你的工作空間中可用。

本練習屬於課程

使用 purrr 的 R 語言中級函式程式設計

檢視課程

練習說明

  • 建立只包含轉推的子列表,擷取 user_id 元素,並用 unique() 去除重複。

  • 建立只包含原創推文的子列表,擷取 user_id 元素,並用 unique() 去除重複。

  • 結合 union()(base R)與 length() 來取得使用者總數。

  • 使用 setdiff()(base R)來取得只出現在轉推子列表中的使用者。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Keep the RT, extract the user_id, remove the duplicate
rt <- ___(___, "is_retweet") %>%
  ___("user_id") %>% 
  ___()

# Remove the RT, extract the user id, remove the duplicate
non_rt <- ___(rstudioconf, "is_retweet") %>%
  ___("user_id") %>% 
  ___()

# Determine the total number of users
___(rt, non_rt) %>% ___()

# Determine the number of users who has just retweeted
___(rt, non_rt) %>% ___()
編輯並執行程式碼