Processing multiple inputs
You work as a Payroll Analyst for an outsourcing firm. Each month, you receive data for the workers on your payroll. You have been asked to write parallel R code that can calculate the total payout per day.
You have two lists in your workspace, ls_hours and ls_rates. Each has 30 elements, one for each day of the month. Each element of ls_hours is composed of the hours worked by each worker on a given day, and each element of ls_rates contains the corresponding hourly rates. You also have function, calc_payout(), that takes two arguments, hours and rates.
calc_payout <- function (hours, rates) paste0("$", sum(hours * rates))
You need to use the appropriate function from the furrr package to do this calculation in parallel. The furrr package has been loaded for you.
Este ejercicio forma parte del curso
Parallel Programming in R
Instrucciones del ejercicio
- Use the
future_map()variant that takes multiple inputs to loop over. - Combine
ls_hoursandls_rates. - Specify the function
calc_payout()to thefuture_map()variant. - Revert to a sequential plan.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
plan(multisession, workers = 5)
# Use the correct future_map() variant
___(
# Combine ls_hours and ls_rates
___(___, ___),
# Specify the function to apply
___)
# Revert to sequential plan
___(___)