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.
This exercise is part of the course
Intermediate Functional Programming with purrr
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Complete the function definition
str_prop_detected <- function(string, pattern) {
string %>%
# Detect the pattern
___(___) %>%
# Calculate the mean
___()
}
# Create flatten_and_compact()
flatten_and_compact <- ___(___, ___)