1. Learn
  2. /
  3. Courses
  4. /
  5. Parallel Programming in R

Connected

Exercise

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.

Instructions

100 XP
  • Use the future_map() variant that takes multiple inputs to loop over.
  • Combine ls_hours and ls_rates.
  • Specify the function calc_payout() to the future_map() variant.
  • Revert to a sequential plan.