LoslegenKostenlos loslegen

Counting favorites

Let's continue our exploration of the RStudio Conf dataset. Remember that this dataset is a list of 5000+ sublists, each sublist being a tweet containing the #RStudioConf hashtag.

In this exercise, we'll extract a statistic about the tweets that were not retweets: the mean of the number of favorites. The "favorite_count" element, contained in each sublist, is the number of people who have liked this specific tweet.

purrr has been loaded for you, and the rstudioconf dataset is still available in your workspace.

Diese Übung ist Teil des Kurses

Intermediate Functional Programming with purrr

Kurs anzeigen

Anleitung zur Übung

  • Prefill the mean() and round() functions with na.rm = TRUE and digits = 1.

  • Build a new function out of these two prefilled function, and call it rounded_mean().

  • Create a sublist of non-retweets.

  • Extract the "favorite_count" element from each sublist with the map_* variant for integer, and pass the result to rounded_mean().

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Prefill mean() with na.rm, and round() with digits = 1
mean_na_rm <- ___(___, ___)
round_one <- ___(___, ___)

# Compose a rounded_mean function
rounded_mean <- ___(___, ___)

# Extract the non retweet  
non_rt <- ___(___, "is_retweet")

# Extract "favorite_count", and pass it to rounded_mean()
non_rt %>%
  map_dbl("___") %>%
  ___()
Code bearbeiten und ausführen