1. Learn
  2. /
  3. Courses
  4. /
  5. Life Insurance Products Valuation in R

Exercise

Plotting life expectancies by age

Cynthia decides to visualize the life expectancy as a function of age. Can you guide Cynthia on how to construct such a graph?

To do this efficiently in R, you should first write a function which computes the curtate life expectancy for a given age and life table. Then, you can apply this function over all ages in the life table. Using sapply() the output is simplified to the most elementary data structure possible.

The preloaded life_table object contains the 1999 period life table for females in Belgium.

Instructions

100 XP
  • Complete the code defining the function curtate_future_lifetime().
  • Create a vector ages by extracting the age column from life_table.
  • Use sapply() with arguments ages, curtate_future_lifetime, and life_table to compute the curtate life expectancy at all ages in the life table.
  • Plot future_lifetimes versus ages.