char_to_num: character to number

Description Usage Arguments Value Examples

Description

char_to_num is for transfering character variables which are actually numerical numbers containing strings to numeric.

Usage

1
2
3
4
5
6
7
8
char_to_num(
  dat,
  char_list = NULL,
  m = 0,
  p = 0.5,
  note = FALSE,
  ex_cols = NULL
)

Arguments

dat

A data frame

char_list

The list of charecteristic variables that need to merge categories, Default is NULL. In case of NULL, merge categories for all variables of string type.

m

The minimum number of categories.

p

The max percent of categories.

note

Logical, outputs info. Default is TRUE.

ex_cols

A list of excluded variables. Regular expressions can also be used to match variable names. Default is NULL.

Value

A data.frame

Examples

1
2
3
4
5
dat_sub = lendingclub[c('dti_joint',	'emp_length')]
str(dat_sub)
#variables that are converted to numbers containing strings
dat_sub = char_to_num(dat_sub)
str(dat_sub)

Example output

Package 'creditmodel' version 1.2.7
'data.frame':	31766 obs. of  2 variables:
 $ dti_joint : chr  "Missing" "Missing" "9.02" "Missing" ...
 $ emp_length: chr  "3 years" "2 years" "2 years" "10+ years" ...
-- Transfering character variables which are actually numerical to numeric
'data.frame':	31766 obs. of  2 variables:
 $ dti_joint : num  NA NA 9.02 NA NA NA NA NA NA NA ...
 $ emp_length: chr  "3 years" "2 years" "2 years" "10+ years" ...

creditmodel documentation built on Jan. 7, 2022, 5:06 p.m.