Phân tích dữ liệu mạng xã hội bằng R
Vivek Vijayaraghavan
Data Science Coach
-filter để trích xuất tweet gốc-filter:retweets loại trừ mọi retweet-filter:quote loại tweet trích dẫn-filter:replies đảm bảo loại tweet trả lời# Trích xuất 100 tweet về "digital marketing"
tweets_all <- search_tweets("digital marketing", n = 100)
reply_to_screen_name, is_quote, is_retweet# Kiểm tra số lượng trả lời
library(plyr)
count(tweets_all$reply_to_screen_name)
x freq
<fct> <int>
blairaasmith 2
javiergosende 1
juanburgos 1
WhutTheHale 2
NA 94
# Kiểm tra số lượng tweet trích dẫn
count(tweets_all$is_quote)
x freq
<lgl> <int>
FALSE 98
TRUE 2
# Kiểm tra số lượng retweet
count(tweets_all$is_retweet)
x freq
<lgl> <int>
FALSE 61
TRUE 39
-filter# Áp dụng '-filter'
tweets_org <- search_tweets("digital marketing
-filter:retweets
-filter:quote
-filter:replies",
n = 100)
# Kiểm tra số lượng trả lời
library(plyr)
count(tweets_org$reply_to_screen_name)
x freq
<lgl> <int>
NA 100
# Kiểm tra số lượng trích dẫn
library(plyr)
count(tweets_org$is_quote)
x freq
<lgl> <int>
FALSE 100
# Kiểm tra số lượng retweet
library(plyr)
count(tweets_org$is_retweet)
x freq
<lgl> <int>
FALSE 100
lang lọc tweet theo ngôn ngữ
# Lọc và trích xuất tweet đăng bằng tiếng Tây Ban Nha
tweets_lang <- search_tweets("brand marketing", lang = "es")
View(tweets_lang)

head(tweets_lang$lang)
[1] "es" "es" "es" "es" "es" "es"
min_faves: lọc tweet có số yêu thích tối thiểumin_retweets: lọc tweet có số retweet tối thiểu AND để thỏa cả hai điều kiện# Trích xuất tweet có tối thiểu 100 yêu thích và retweet
tweets_pop <- search_tweets("bitcoin min_faves:100 AND
min_retweets:100")
# Tạo data frame để kiểm tra số retweet và yêu thích
counts <- tweets_pop[c("retweet_count", "favorite_count")]
head(counts)
retweet_count favorite_count
<int> <int>
1 162 833
2 141 894
3 164 1128
4 395 1346
5 475 2271
6 270 1654
# Xem các tweet
head(tweets_pop$text)
text
<chr>
1 As we continue to build the Bakkt Bitcoin Futures contract, we reached a
2 BREAKING: The United States is considering entering into a "currency pact"
3 REMINDER: The Bitcoin ETF will eventually get approved.\n\nNot a question
4 [New Post] Bitcoin is becoming much more important in Hong Kong and India.
5 Reports are surfacing that some Hong Kong ATMs have run out of cash as
6 Bitcoin is the most transparent currency ever created.
Phân tích dữ liệu mạng xã hội bằng R