MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Intermediate Functional Programming with purrr

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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

# Create flatten_and_compact()
flatten_and_compact <- ___(___, ___)
Edit dan Jalankan Kode