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
This exercise is part of the course
Introduction to R for Finance
Exercise instructions
- Use the
sum()
function to calculate the totalpresent_value
ofcash
. Assign it tototal_pv
. - Subset
cash
to only include rows about company B to createcash_B
. - Use
sum()
andcash_B
to calculate the totalpresent_value
from company B. Assign it tototal_pv_B
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Total present value of cash
total_pv <-
# Company B information
cash_B <-
# Total present value of cash_B
total_pv_B <-