R/tidyMainApplicant.R

Defines functions main.applicant

#' main applicant logic
#'
#' @description This function implements the main applicant logic for selected applicant data
#' @param df The name of the dataframe you want to manipulate
#' @return datatframe, tibble
#' @keywords applicants
#' @import dplyr
#' @export
#' @examples main.applicant(df = df)

main.applicant <- function(df = df) {
  
  df <- df %>%
    dplyr::mutate(hauptantragstellerEinkommen = dplyr::if_else((einkommen.as1  >= einkommen.as2), 
                                                               einkommen.as1 , einkommen.as2, 
                                                               missing = einkommen.as1 ),
                  hauptantragstellerAnrede = dplyr::if_else((einkommen.as1  >= einkommen.as2),
                                                            anrede.as1, anrede.as2,
                                                            missing = anrede.as1),
                  hauptantragstellerBeschaeftigungsart = dplyr::if_else((einkommen.as1  >= einkommen.as2), 
                                                                        beschaeftigungsart.as1, beschaeftigungsart.as2, 
                                                                        missing = beschaeftigungsart.as1),
                  hauptantragstellerFamilienstand = dplyr::if_else((einkommen.as1  >= einkommen.as2),
                                                                   familienstand.as1, familienstand.as2,
                                                                   missing = familienstand.as1),
                  hauptantragstellerWohnart = dplyr::if_else((einkommen.as1  >= einkommen.as2),
                                                             wohnart.as1, wohnart.as2,
                                                             missing = wohnart.as1),
                  hauptantragstellerBeschaefigungsstatus = dplyr::if_else((einkommen.as1  > einkommen.as2),
                                                                          beschaeftigungsstatus.as1, beschaeftigungsstatus.as2,
                                                                          missing = beschaeftigungsstatus.as1),
                  hauptantragstellerProbezeit = dplyr::if_else((einkommen.as1  > einkommen.as2),
                                                               isProbezeit.as1, isProbezeit.as2,
                                                               missing = isProbezeit.as1),
                  hauptantragstellerBefristung = dplyr::if_else((einkommen.as1  > einkommen.as2),
                                                                befristetBis.as1, befristetBis.as2,
                                                                missing = befristetBis.as1),
                  hauptantragstellerStaatsangehoerigkeit = dplyr::if_else((einkommen.as1  >= einkommen.as2),
                                                                          staatsangehoerigkeit.as1, staatsangehoerigkeit.as2,
                                                                          missing = staatsangehoerigkeit.as1),
                  hauptantragstellerPersonenimHaushalt = dplyr::if_else((einkommen.as1  > einkommen.as2),
                                                                        anzahlPersonenImHaushalt.as1, anzahlPersonenImHaushalt.as2,
                                                                        missing = anzahlPersonenImHaushalt.as1),
                  hauptantragstellerPkw = dplyr::if_else((einkommen.as1  >= einkommen.as2),
                                                         anzahlPkw.as1, anzahlPkw.as2,
                                                         missing = anzahlPkw.as1),
                  hauptantragstellerBranche = dplyr::if_else((einkommen.as1  >= einkommen.as2),
                                                             branche.as1, branche.as2,
                                                             missing = branche.as1),
                  hauptantragstellerAufenthaltstitel = dplyr::if_else((einkommen.as1  >= einkommen.as2),
                                                                      aufenthaltstitel.as1, aufenthaltstitel.as2,
                                                                      missing = aufenthaltstitel.as1),
                  hauptantragstellerArbeitserlaubnis = dplyr::if_else((einkommen.as1  >= einkommen.as2),
                                                                      arbeitserlaubnis.as1, arbeitserlaubnis.as2,
                                                                      missing = arbeitserlaubnis.as1) 
    ) %>% 
    dplyr::select(-dplyr::starts_with('antragsteller'), -dplyr::contains('.as'))
  
  return(df)
}  
europace-privatkredit/tidyPkuData documentation built on Oct. 2, 2019, 3 a.m.