Very glad you manage to find a way to get through.
Please read the linked post about the transition from rtweet 0.7.0 to 1.0 it will help if you find the code provided doesn’t work. The returned data does contain the originating tweet’s user name, but to access it you need to use users_data()
:
ud <- users_data(test)
head(ud)
## # A tibble: 6 × 23
## id id_str name scree…¹ locat…² descr…³ url prote…⁴ follo…⁵ frien…⁶ liste…⁷ creat…⁸ favou…⁹ verif…˟
## <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <lgl> <int> <int> <int> <chr> <int> <lgl>
## 1 1.81e 7 18075604 Nige… nigelw… "Londo… "MD @g… http… FALSE 26440 6456 2055 Fri De… 147361 FALSE
## 2 9.51e17 9509105211… Kena… KenanH… "Reykj… "Canad… NA FALSE 37 212 0 Wed Ja… 438 FALSE
## 3 2.49e 7 24933826 Shar… sharon… "Amste… "Consu… http… FALSE 17808 5809 631 Tue Ma… 38872 TRUE
## 4 6.29e 7 62907089 Klau… knoede… "Erlen… "" NA FALSE 112 136 17 Tue Au… 52642 FALSE
## 5 2.80e 7 27964251 Chri… rl_chr… "Newca… "Work:… NA FALSE 1552 2278 0 Tue Ma… 20677 FALSE
## 6 7.39e 7 73863343 Evya… evyata… "" "Husba… http… FALSE 156 895 2 Sun Se… 3626 FALSE
## # … with 9 more variables: statuses_count <int>, profile_image_url_https <chr>, profile_banner_url <chr>,
## # default_profile <lgl>, default_profile_image <lgl>, withheld_in_countries <list>, derived <chr>,
## # withheld_scope <lgl>, entities <list>, and abbreviated variable names ¹screen_name, ²location, ³description,
## # ⁴protected, ⁵followers_count, ⁶friends_count, ⁷listed_count, ⁸created_at, ⁹favourites_count, ˟verified
## # ℹ Use `colnames()` to see all variable names
I’d also recommend you explore the usage of network_data()
and network_graph()
:
nd <- network_data(test)
head(nd)
## from to type
## 1 18075604 24933826 mention
## 2 18075604 73863343 mention
## 3 18075604 42000992 mention
## 4 18075604 960515675415613440 mention
## 5 18075604 3595680016 mention
## 6 18075604 2187847450 mention
ng <- network_graph(test)
## IGRAPH 250186f DN-- 345 15172 --
## + attr: id (v/c), name (v/c), type (e/c)
## + edges from 250186f (vertex names):
## [1] nigelwalsh->sharonodea nigelwalsh->evyatar_amira nigelwalsh->Gilad_Shai
## [4] nigelwalsh->magicveronique nigelwalsh->MsRMerry nigelwalsh->JoeCMerriman
## [7] nigelwalsh->rl_chris_higham nigelwalsh->JimMarous nigelwalsh->jenny__watts
## [10] nigelwalsh->goforsergei nigelwalsh->andrewthornley nigelwalsh->barbmaclean
## [13] nigelwalsh->pdeepa nigelwalsh->Jo_R_H nigelwalsh->Broker_Brett
## [16] nigelwalsh->InsuranceEleph1 nigelwalsh->chrisc99 nigelwalsh->NeilMit42376137
## [19] nigelwalsh->Katherine_Coach nigelwalsh->Paul_GreyKnight nigelwalsh->jeffroth77
## [22] nigelwalsh->Marged nigelwalsh->EmmaAnnJohnston nigelwalsh->edgaze
## + ... omitted several edges
plot(ng)
You might want to use the screen name via the attributes of nd to obtain a data.frame for your edges:
id <- attr(nd, "idsn")
names(id)
## [1] "id" "sn"
nd$from_id <- id$sn[match(nd$from, id$id)]
head(nd)
## from to type from_id
## 1 18075604 24933826 mention nigelwalsh
## 2 18075604 73863343 mention nigelwalsh
## 3 18075604 42000992 mention nigelwalsh
## 4 18075604 960515675415613440 mention nigelwalsh
## 5 18075604 3595680016 mention nigelwalsh
## 6 18075604 2187847450 mention nigelwalsh
nd$to_id <- id$sn[match(nd$to, id$id)]
head(nd)
## from to type from_id to_id
## 1 18075604 24933826 mention nigelwalsh sharonodea
## 2 18075604 73863343 mention nigelwalsh evyatar_amira
## 3 18075604 42000992 mention nigelwalsh Gilad_Shai
## 4 18075604 960515675415613440 mention nigelwalsh magicveronique
## 5 18075604 3595680016 mention nigelwalsh MsRMerry
## 6 18075604 2187847450 mention nigelwalsh JoeCMerriman
edges <- nd |>
filter(to_id != "GarminFitness") |>
mutate(from = from_id, to = to_id) |>
select(-from_id, -to_id)
You might want to filter also to keep just the mentions (or directly use nd <- network_data(test, e = "mention")
).
Good luck with your course