Analisi dei dati dei social media in R
Sowmya Vivek
Data Science Coach
screen_name memorizza l’handle dell’utente
rtweet
# Estrai tweet su "#brexit" con search_tweets()
tweets_df <- search_tweets("#brexit")
# Visualizza i nomi delle colonne
names(tweets_df)

screen_name per capire l’interesse dell’utentefollowers_count per confrontare l’influenza socialretweet_count e text per trovare i tweet più popolariscreen_name è l’handle di Twitter# Estrai tweet su "#Arsenal" con search_tweets()
twts_arsnl <- search_tweets("#Arsenal", n = 18000)
# Crea una tabella di utenti e conteggi di tweet per l’argomento
sc_name <- table(twts_arsnl$screen_name)
head(sc_name)
_____today_____ ___JJ23 ___SAbI__ __ambell __Amzo__ __bobbysingh
1 2 3 1 1 1
# Ordina la tabella in ordine decrescente di tweet
sc_name_sort <- sort(sc_name, decreasing = TRUE)
# Vedi i 6 utenti top e le frequenze
head(sc_name_sort)
_whatthesport footy90com Official_ATG1 TheShortFuse RubellM ArsenalZone_Ind
176 90 88 53 48 43
# Estrai dati utente con lookup_users()
tvseries <- lookup_users("GameOfThrones", "fleabag", "BreakingBad")
# Crea un dataframe con le colonne screen_name e followers_count
user_df <- tvseries[,c("screen_name","followers_count")]
# Visualizza il numero di follower per confronto
user_df
screen_name followers_count
<chr> <int>
GameOfThrones 8597188
fleabag 58727
BreakingBad 1240349
retweet_count memorizza il numero di retweet# Crea un data frame con testo del tweet e retweet
rtwt <- tweets_arsenal[,c("text", "retweet_count")]
# Ordina in modo decrescente per numero di retweet
library(dplyr)
rtwt_sort <- arrange(rtwt, desc(retweet_count))
# Escludi righe con testo del tweet duplicato
rtwt_unique <- unique(rtwt_sort, by = "text")
# Stampa le prime 6 pubblicazioni uniche più retwittate
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 😭😭😍😍 Questo è ciò che chiamo felicità #aubameyang #arsenal
1166 When sky sports introduced the new Monday night football! The Sha
Analisi dei dati dei social media in R