R/tidyProduct.R

Defines functions tidyProduct

#' product
#'
#' @description This function obtains the product category from product names
#' @param df The name of the dataframe you want to manipulate
#' @return datatframe, tibble
#' @keywords product category
#' @import dplyr, stringr
#' @export
#' @examples tidyProduct(df = df)

tidyProduct <- function(df) {
  
  df <- df %>% 
    dplyr::mutate(produktart = dplyr::case_when(
      stringr::str_detect(produktbezeichnung, pattern = 'Auto') ~ 'Autokredit',
      stringr::str_detect(produktbezeichnung, pattern = 'DSL Business Kredit') ~ 'Businesskredit',
      stringr::str_detect(produktbezeichnung, pattern = 'SofortKredit') ~ 'Sofortredit',
      stringr::str_detect(produktbezeichnung, pattern = 'Modernisierungskredit') |
        stringr::str_detect(produktbezeichnung, pattern = 'WohnKredit') |
        stringr::str_detect(produktbezeichnung, pattern = 'Modernisierung') |
        stringr::str_detect(produktbezeichnung, pattern = 'Immo') |
        stringr::str_detect(produktbezeichnung, pattern = 'Wohn') ~ 'Wohnkredit',
      TRUE ~ 'Ratenkredit')
    )
  
  return(df)
}
europace-privatkredit/tidyPkuData documentation built on Oct. 2, 2019, 3 a.m.