Healthcare spending with clusterMap()
In a recent healthcare conference, it was claimed that total healthcare expenditure is increasing globally.
You were in attendance, and would like to get some rough estimates to test this claim. You have sourced a dataset that gives you per capita healthcare spending and the population for the year 2000 and onwards. You have two lists: ls_pop and ls_exp. They contain population sizes and per capita healthcare spending, respectively, for each country.
The function total_exp() that takes two arguments: pop or population and exp_pc, per capital healthcare spending. This function returns the total spending in billions of US dollars. You would like to apply this function to ls_pop and ls_exp in parallel. The parallel package has been loaded.
Este ejercicio forma parte del curso
Parallel Programming in R
Instrucciones del ejercicio
- Apply
total_exp()in parallel to each element ofls_popandls_exp. - Specify the list whose elements will be supplied to the
popargument oftotal_exp(). - Similarly, specify the list to be supplied to the
exp_pcargument oftotal_exp().
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
total_exp <- function (pop, exp_pc) {
sum(pop * exp_pc)/1e9
}
cl <- makeCluster(4)
# Apply total_exp using cl to multiple arguments
ls_total <- ___(___, ___,
# Specify first argument
pop = ___,
# Specify second argument
exp_pc = ___)
stopCluster(cl)
print(paste("Average yearly increase in USD billions:", round(mean(diff(unlist(ls_total))))))