Session Ready
Exercise

Present value of projected cash flows (2)

Amazing! You are almost done with this chapter, and you are becoming a true wizard of data frames and finance. Before you move on, let's answer a few more questions.

You now have a column for present_value, but you want to report the total amount of that column to your board members. Calculating this part is easy, use the sum() function you learned earlier to add up the elements of cash$present_value.

However, you also want to know how much company A and company B individually contribute to the total present value. Do you remember how to separate the rows of your data frame to only include company A or B?

cash_A <- subset(cash, company == "A")

sum(cash_A$present_value)

[1] 4860.218
Instructions
100 XP
  • Use the sum() function to calculate the total present_value of cash. Assign it to total_pv.
  • Subset cash to only include rows about company B to create cash_B.
  • Use sum() and cash_B to calculate the total present_value from company B. Assign it to total_pv_B.