We have a winner!
In this exercise, we will identify an important metric — who is the user who has published the tweet with the most retweets?
This kind of information is important when you are doing social media analysis: it will give you information about the most "famous" tweet of your dataset. This can help, in the future, to establish what are the key themes and users for a specific theme/hashtag.
We will use purrr
to extract the most retweeted tweet from our corpus, and see who is the user behind this tweet. As we want this analysis to be run on original tweets only, we have provided you the non_rt
list, which was created in a previous exercise.
This exercise is part of the course
Intermediate Functional Programming with purrr
Exercise instructions
Extract all the
"retweet_count"
elements with the appropriatemap_*()
variant. Pass it tomax()
.Prefill a
map_at()
, with.at
being"retweet_count"
and the.f
being a mapper that tests for equality tomax_rt
.Map this new function on
non_rt
, keep the"retweet_count"
only, and flatten the result.Print the
$screen_name
and$text
of the result to the console.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Get the max() of "retweet_count"
max_rt <- ___(non_rt, ___) %>%
___()
# Prefill map_at() with a mapper testing if .x equal max_rt
max_rt_calc <- ___(___, .at = "retweet_count", .f := ~ ___ )
res <- non_rt %>%
# Call max_rt_calc() on each element
___(___) %>%
# Keep elements where retweet_count is non-zero
___("___") %>%
# Flatten it
___()
# Print the "screen_name" and "text" of the result
res$screen_name
res$text