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

Exercise

foreach with variables and packages

The rate at which a population grows is called the growth rate, expressed as a percentage. Almost every country is experiencing a drop in growth rate, but some are declining faster than others.

You were hired as a Demographics Analyst, and your task is to calculate the the ratio between a country's population growth rate and the global growth rate for the years 2017 to 2021. You have been given a list of data frames, ls_df, each is a data frame like this:

    country year growth_rate
Afghanistan 2017        2.52
...

You also have a global growth data frame, df_global:

year global_growth
2017          1.15
...

foreach and dplyr have been loaded for you. The cluster has already been created and registered with the foreach backend.

Instructions

100 XP
  • Export df_global to the cluster within the foreach() function call.
  • Specify the dplyr package required for the calculation.
  • Specify rbind as the combine method.
  • Use the parallel operator.