diff --git a/scripts/phase2/transform_data.r b/scripts/phase2/transform_data.r index 67f645e8cf8e28be5bc73421ff9b09ba5925a695..1d9ab5b618c102b4bc4a89045018213a3b2c0483 100644 --- a/scripts/phase2/transform_data.r +++ b/scripts/phase2/transform_data.r @@ -1,17 +1,18 @@ library("readxl") +library("writexl") library("dplyr") # Phase 2 Excel -# https://unl.box.com/s/4dfo4iv2n8awiqt20himu24kyhtmgavk -fileName <- "C:/Users/its-student/Desktop/Phase2.xlsx" +input <- "C:/Users/its-student/Desktop/Phase2In.xlsx" +output <- "C:/Users/its-student/Desktop/Phase2Out.xlsx" # read in sheets -data <- read_excel(fileName, sheet = "Data") -commission <- read_excel(fileName, sheet = "Commission") # by group and policy duration -expense <- read_excel(fileName, sheet = "Expense") # bin by annualized net premium -rtn <- read_excel(fileName, sheet = "RTN") -sic <- read_excel(fileName, sheet = "SIC") -tax <- read_excel(fileName, sheet = "Tax") +data <- read_excel(input, sheet = "Data") +commission <- read_excel(input, sheet = "Commission") # by group and policy duration +expense <- read_excel(input, sheet = "Expense") # bin by annualized net premium +rtn <- read_excel(input, sheet = "RTN") +sic <- read_excel(input, sheet = "SIC") +tax <- read_excel(input, sheet = "Tax") # drop reserves not related to STD (IBNR) data <- data %>% select(-c(ICOS, WAIVER_IBNR, GAAP_RESV, WAIVER_RESERVE)) @@ -97,3 +98,7 @@ data <- data %>% mutate(ACTUAL_CLAIMS = PAID_CLAIMS + IBNR) # calculate actual to expected ratio data <- data %>% mutate(ACTUAL_TO_EXPECTED = ACTUAL_CLAIMS / EXPECTED_CLAIMS) + +# write data to Excel +write_xlsx(data, path = output, col_names = TRUE) +