LoslegenKostenlos starten

Playing with URLs

In the last exercise, we've extracted the raw number of tweets which contain the pattern "github". So far, this is just a raw number: 347, and you're still not able to determine which proportion of the total number of URLs this 347 represents.

In this exercise, we'll build a function called str_prop_detected(), which takes a character vector and a pattern, and returns the proportion of elements which contain this pattern. This function could be used on other datasets to detect the proportion of pattern matches in a character vector.

Here, we'll combine some purrr functions with the str_detect() function from stringr. These two packages have been loaded for you, and the rstudioconf dataset is still available in your workspace.

Diese Übung ist Teil des Kurses

<Kurs>Intermediate Functional Programming with purrr</Kurs>
Kurs ansehen

Interaktive praktische Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Complete the function definition
str_prop_detected <- function(string, pattern) {
  string %>%
    # Detect the pattern
    ___(___) %>%
    # Calculate the mean
    ___()
} 

# Create flatten_and_compact()
flatten_and_compact <- ___(___, ___)
Code bearbeiten und ausführen