I have one table with five columns Year, GDP, Revenue, Income and Wages.With this table I made calculation with code below.
library(dplyr)
#DATA
TEST<-data.frame(
Year= c(2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021),
GDP =c(8634,5798,6022,6002,6266,6478,6732,7224,6956,6968,7098,7620,7642,8203,9856,20328,22364,22222,23250,25250,26250,27250),
Revenue =c(8734,5798,7011,7002,7177,7478,7731,7114,7957,7978,7098,7710,7742,8203,9857,10328,11374,12211,13150,15150,17150,17150),
Income =c(8834,5898,6033,6002,6366,6488,6833,8334,6956,6968,8098,8630,8642,8203,9856,30328,33364,32233,33350,35350,36350,38350),
Wages =c(8834,5598,8044,8002,8488,8458,8534,5444,8958,8988,5098,5840,5842,8203,9858,40328,44384,42244,43450,45450,48450,45450)
)
#CALCULATION
ESTIMATION_0<-data.frame(mutate(TEST,
ETR_Revenue=(Revenue/GDP),
ETR_Income=(Income/GDP),
ETR_Wages=(Wages/GDP)
))
View(ESTIMATION_0)
But my intention is to optimize this code with some own function e.g fun2 <- function(x,y){((x/y))}, which can be able to divide Revenue with GDP, Income with GDP etc.So can anybody help me with this problem ?
Using tidy evaluation approach similar to this answer
Created on 2019-03-01 by the reprex package (v0.2.1.9000)