I have very little experience in R, and am currently trying to create a function which calculates the CAGR (compounded annual growth rate) of my financial data (the gross profit at time t=0 and t=-2).
I have imported the gross profits from an excel file (called Forsog_orbis_til_rv2) and want to create a new variable called CAGR in this data frame. I have used the following code:.
library(tibble);
library(dplyr)
grossprofit.t <- c(818000,883000,4141000,123000,5301000,4788000)
grossprofit.t2 <- c(2375000,2279000,-69000,5604000,3959000,6240000)
mydata <- data.frame(grossprofit.t,grossprofit.t2)
CAGR_formula <- function(FV, PV, yrs = 2) {
values <- ((FV/PV)^(1/yrs)-1)
return(values)
}
mydata %>%
mutate(CAGR=CAGR_formula(grossprofit.t,grossprofit.t2,2)*100)`
print(mydata)
When I do this, the output only includes my two gross profit-variables.. What am I doing wrong with the mutate function or the CAGR function?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)