Row-binding future_map results
You work for a higher studies consultancy which recommends US universities to applicants abroad. You have sourced a university ranking dataset which contains a column score
for research, citations, etc, for different universities.
The team statistician has written a function, calc_quants()
, that is available to you. This function calculates a range for the scores of a given university. It takes two arguments, 1) a data frame with the column score
, and 2) the quantile values of interest q_values
. The quantiles of interest are available to you as the variable my_q_values
.
my_q_values <- c(0.025, 0.975)
You are asked to apply this function to the data for each university in parallel.
furrr
and tidyverse
have been loaded for you.
This exercise is part of the course
Parallel Programming in R
Exercise instructions
- Create a configuration that specifies
my_q_values
as a global variable required by all workers. - Split the data frame
uni_data
byuniversity_name
. - Apply
calc_quants()
to each university's scores using the correctfuture_map()
variant to bind results by rows. - Specify the values for the
q_values
and configuration for.options
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
plan(cluster, workers = 6)
# Create a configuration object to export global variables
config <- ___(___ = ___)
uni_data %>%
# Split the data frame
___(___) %>%
# Specify the future_map variant and the function to map
___(___,
# Specify values for the q_values argument and configuration for .options
q_values = ___,
.options = ___,
.id = "university")
plan(sequential)