I need help Completing this R Assignment: Write an R program that takes three ve
ID: 3813154 • Letter: I
Question
I need help Completing this R Assignment: Write an R program that takes three vectors and computes three NPVs, one for each vector. This program returns the highest NPV vector along with the NPV value. This is the Pseudocode # Store three test vectors # Store a rate in r #Create a function that takes the three vectors and r as inputs #Load FinCal into the function #Calculate and store three NPVs #Create an if-else loop that determines the correct(largest) NPV to display #Display the vector associated with the highest NPV This is what I have so far #Name Vectors vector_1Explanation / Answer
As requierd using if else loop i've return the code below.
vector_1 <- c(560,720,700) #defining the vectors
vector_2 <- c(460,370,120)
vector_3 <- c(908,345,760)
library(FinCal) #importing the required library
rate = 12 #defining the rate
#Calculating the net present values
npv1 <- npv(rate,vector_1)
npv2 <- npv(rate,vector_2)
npv3 <- npv(rate,vector_3)
#Finding the maximum net present value and also printing the vector it belongs. i've used sprintf in this, because i am printing both int and string in 1 line.
if ((npv1>npv2) & (npv1>npv3)){
sprintf("%f is the maximum npv and is from vector_1",npv1)
} else if ((npv2>npv1) & (npv2>npv3)){
sprintf("%f is the maximum npv and is from vector_2",npv2)
} else{
sprintf("%f is the maximum npv and is from vector_3",npv3)
}
Thanks
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.