#' product provider factor levels
#'
#' @description This function recodes factor levels in product provider vector
#' @param df The name of the dataframe you want to manipulate, agg defines whether regional product providers are aggregated or not
#' @return datatframe, tibble
#' @keywords product provider levels
#' @import dplyr, stringr
#' @export
#' @examples fun_tidyPa(df = df)
tidyPa <- function(df, aggregate = TRUE) {
if (aggregate) {
df <- df %>%
dplyr::mutate(produktanbieterid = dplyr::case_when(
stringr::str_detect(produktanbieterid, pattern = 'PSD') ~ 'PSD',
stringr::str_detect(produktanbieterid, pattern = 'SPK') | stringr::str_detect(produktanbieterid, pattern = 'KSK') ~ 'Sparkasse',
stringr::str_detect(produktanbieterid, pattern = 'DSL') ~ 'DSL',
stringr::str_detect(produktanbieterid, pattern = 'DKB') ~ 'DKB',
stringr::str_detect(produktanbieterid, pattern = 'NETBANK') ~ 'Netbank',
stringr::str_detect(produktanbieterid, pattern = 'TARGOBANK') ~ 'Targo',
stringr::str_detect(produktanbieterid, pattern = 'SANTANDER_CONSUMER') ~ 'Santander-Consumer',
stringr::str_detect(produktanbieterid, pattern = 'SKG') ~ 'SKG',
stringr::str_detect(produktanbieterid, pattern = 'DIBA') ~ 'ING-Diba',
stringr::str_detect(produktanbieterid, pattern = 'OAB') ~ 'OAB',
stringr::str_detect(produktanbieterid, pattern = 'AUXMONEY') ~ 'AUXMONEY',
stringr::str_detect(produktanbieterid, pattern = 'SANTANDER_CARCREDIT') ~ 'Santander-Car',
stringr::str_detect(produktanbieterid, pattern = 'COMMERZBANK') ~ 'Coba',
stringr::str_detect(produktanbieterid, pattern = 'ALTE_LEIPZIGER') ~ 'Alte-Leipziger',
stringr::str_detect(produktanbieterid, pattern = 'SUEDWESTKREDITBANK') ~ 'SWK',
stringr::str_detect(produktanbieterid, pattern = 'VON_ESSEN_BANK') ~ 'VEB',
TRUE~ 'nicht_vorhanden')) #%>%
# filter(produktanbieterid != 'Test')
return(df)
}
else {
df <- df %>%
dplyr::mutate(produktanbieterid = str_remove_all(produktanbieterid, pattern = '_RATENKREDIT')) %>%
dplyr::filter(produktanbieterid != 'ABRECHNUNGSBANK_RATENKREDIT')
return(df)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.