in Education by
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)

1 Answer

0 votes
by
you need to assign your pipe sequence to a variable. mydata <- mydata %>% mutate(CAGR=CAGR_formula(grossprofit.t2,grossprofit.t,2)*100) print(mydata)

Related questions

0 votes
    ____________ provides a point-and-click interface to many basic statistic problems. (a) Commander (b) GUI (c) ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    ________ function generates n normal random numbers based on the mean and standard deviation arguments passed to ... R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    _________ is an indication that a fatal problem has occurred and execution of the function stops. (a) message (b ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    ______ suspends the execution of a function wherever it is called and puts the function in debug mode. (a) ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Multiple objects can be de parsed at once and read back using function _____ (a) source() (b) read() ( ... Operations of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Which function is used to select variables and observations from a given dataset? (a) Subset() (b) Sample( ... of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    ________ function is usually used inside another function and throws a warning whenever a particular package is not ... R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    I am using the packages "fpp" and "fpp2". The homework question (question 11(f)) is located at https://otexts.org/ ... as stated in 11(d)): convert visitors to time series tvis...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    Is it possible to change the default values of formal parameters in an R function at runtime? Let's assume, we have the function f...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    __________ function is used to watch for all available packages in library. (a) lib() (b) fun.lib() (c ... Started of R Programming Select the correct answer from above options...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    ___________ function gives an error message if the desired package cannot be loaded. (a) Dplyr (b) Require (c ... of R Programming Select the correct answer from above options...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    Which function helps you perform sorting in R language? (a) Order (b) Inorder (c) Simple (d) Library ... Debugging of R Programming Select the correct answer from above options...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    To get the current date, the _______ function will return a Date object which can be converted to a different ... of R Programming Select the correct answer from above options...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    ________ allows you to insert debugging code into a function a specific places (a) debug() (b) trace() ( ... Debugging of R Programming Select the correct answer from above options...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    Dataframes can be converted into a matrix by calling the following function data ______ (a) matr() (b) matrix ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
...