BaşlayınÜcretsiz Başlayın

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.

Bu egzersiz

Parallel Programming in R

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • 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.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

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
___(___)
Kodu Düzenle ve Çalıştır