Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

How to create an edge list for each user mentioned in a tweet when there are observations containing several user mentioned

$
0
0

I want to do an network analysis of the tweets of some users of my interest and the mentioned users in their tweets.

I retrieved the tweets (no retweets) from several user timelines using the rtweet package in r and want to see who they mention in their tweets.

There is even a variable with the screen names of those useres who are mentioned which will serve me as the target group for my edge list. But sometimes they mention several users and then the observation looks for example like this: c('luigidimaio', 'giuseppeconteit') whereas there is only one user mentioned it is naming just this one user as an observation (eg. agorarai). I want to split those observations containing several mentioned users into single observations for each user. So out of one observation containing both mentioned users as a vector I would have to split it into two observation each containing one of the mentioned users.

The code looks like this so far:

# get user timelines of the most active italian parties (excluding retweets)
tmls_nort <- get_timelines(c("Mov5Stelle", "pdnetwork", "LegaSalvini"), 
                      n = 3200, include_rts = FALSE
                      )

# create an edge list
tmls_el = as.data.frame(cbind(Source = tolower(tmls_nort$screen_name), Target = tolower(tmls_nort$mentions_screen_name)))

Here is an extract of my dataframe:

Source Target n 
<fct> <fct> <int> 
1 legasalvini circomassimo 2 
2 legasalvini 1giornodapecora 2 
3 legasalvini 24mattino 2 
4 legasalvini agorarai 28 
5 legasalvini ariachetira 2
6 legasalvini "c(\"raiportaaporta\", \"brunovespa\")" 7 
```

Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>