Phân tích dữ liệu mạng xã hội bằng R
Sowmya Vivek
Data Science Coach
screen_name lưu tên tài khoản (handle) của người dùng
rtweet
# Trích xuất tweet về "#brexit" bằng search_tweets()
tweets_df <- search_tweets("#brexit")
# Xem tên cột
names(tweets_df)

screen_name để hiểu mối quan tâm của người dùngfollowers_count để so sánh mức độ ảnh hưởngretweet_count và text để nhận diện tweet phổ biếnscreen_name là tên tài khoản Twitter (handle)# Trích xuất tweet về "#Arsenal" bằng search_tweets()
twts_arsnl <- search_tweets("#Arsenal", n = 18000)
# Tạo bảng người dùng và số tweet theo chủ đề
sc_name <- table(twts_arsnl$screen_name)
head(sc_name)
_____today_____ ___JJ23 ___SAbI__ __ambell __Amzo__ __bobbysingh
1 2 3 1 1 1
# Sắp xếp bảng theo số tweet giảm dần
sc_name_sort <- sort(sc_name, decreasing = TRUE)
# Xem 6 người dùng hàng đầu và tần suất tweet
head(sc_name_sort)
_whatthesport footy90com Official_ATG1 TheShortFuse RubellM ArsenalZone_Ind
176 90 88 53 48 43
# Trích xuất dữ liệu người dùng bằng lookup_users()
tvseries <- lookup_users("GameOfThrones", "fleabag", "BreakingBad")
# Tạo dataframe với cột screen_name và followers_count
user_df <- tvseries[,c("screen_name","followers_count")]
# Xem số người theo dõi để so sánh
user_df
screen_name followers_count
<chr> <int>
GameOfThrones 8597188
fleabag 58727
BreakingBad 1240349
retweet_count lưu số lần retweet# Tạo data frame gồm văn bản tweet và số retweet
rtwt <- tweets_arsenal[,c("text", "retweet_count")]
# Sắp xếp theo số retweet giảm dần
library(dplyr)
rtwt_sort <- arrange(rtwt, desc(retweet_count))
# Loại bỏ hàng có văn bản tweet trùng lặp
rtwt_unique <- unique(rtwt_sort, by = "text")
# In 6 bài đăng duy nhất có số retweet cao nhất
head(rtwt_unique)
retweet_count text
<int> <chr>
5606 Once a Gunner, Always a Gunner. We are proud of you @alexanderiwob
3764 Emirates on Fire 🔥🔥🔥🔥 Never give up Gunners💪🏽💪🏽💪🏽 #Arsenal #CO
2798 That mood tonight ⚡️⚡️⚡️ 3️⃣ POINTS 🔴⚪️ #Arsenal #Gunners #COYG h
2741 #Arsenal fan: "I reckon we'll win the League this season." @Robbie
1687 Auba 😭😭😍😍 This is what I call happiness #aubameyang #arsenal
1166 When sky sports introduced the new Monday night football! The Sha
Phân tích dữ liệu mạng xã hội bằng R