R/mod_portofoliu_utils_helpers.R

Defines functions rename_col_nonifrs rename_col max_col

# These commands are used for mod_portofoliu only

# This function aggregates cerere_plata_cumulata in the order of the columns in dataframe
max_col <- function(df){
  if (ncol(df)<2) {return(df)}
  else {for (i in 2:ncol(df)){
    df[,i] = apply(df[,(i-1):i],1,sum) } # This works on a row level, and adds 
  }
  return(df)
}

# Function to rename cerere_plata_cumulata according to its year
rename_col <- function(df){
  return(dplyr::rename_at(.tbl = df,.vars = "Cerere_Plata_cumulata",~paste0("Cerere_Plata_cumulata_",unique(df$an_cerere_plata)))) }

# I need this function in order to rename columns according to their date of refference (anul_de_raportare): ex: expunere_2018_12_31
rename_col_nonifrs <-  function(df){
  return(dplyr::rename_at(.tbl = df,.vars = c("expunere","categorie_contaminata","provizion_contabil"),
                          ~paste0(c("Expunere_","categorie_contaminata_","Provizion_contabil_"),
                                  unique(df$anul_de_raportare)
                          )))  
}
fizic37/RiskManagement documentation built on Feb. 12, 2021, 11:05 a.m.