The diagnose() produces information for diagnosing the quality of the variables of data.frame or tbl_df.

diagnose(.data, ...)

# S3 method for data.frame
diagnose(.data, ...)

Arguments

.data

a data.frame or a tbl_df.

...

one or more unquoted expressions separated by commas. You can treat variable names like they are positions. Positive values select variables; negative values to drop variables. If the first expression is negative, diagnose() will automatically start with all variables. These arguments are automatically quoted and evaluated in a context where column names represent column positions. They support unquoting and splicing.

Value

An object of tbl_df.

Details

The scope of data quality diagnosis is information on missing values and unique value information. Data quality diagnosis can determine variables that require missing value processing. Also, the unique value information can determine the variable to be removed from the data analysis.

Diagnostic information

The information derived from the data diagnosis is as follows.:

  • variables : variable names

  • types : data type of the variable or to select a variable to be corrected or removed through data diagnosis.

    • integer, numeric, factor, ordered, character, etc.

  • missing_count : number of missing values

  • missing_percent : percentage of missing values

  • unique_count : number of unique values

  • unique_rate : ratio of unique values. unique_count / number of observation

See vignette("diagonosis") for an introduction to these concepts.

See also

Examples

# \donttest{ # Diagnosis of all variables diagnose(jobchange)
#> # A tibble: 14 x 6 #> variables types missing_count missing_percent unique_count unique_rate #> <chr> <chr> <int> <dbl> <int> <dbl> #> 1 enrollee_id charac… 0 0 19158 1 #> 2 city factor 0 0 123 0.00642 #> 3 city_dev_index numeric 0 0 93 0.00485 #> 4 gender factor 4508 23.5 4 0.000209 #> 5 relevent_expe… factor 0 0 2 0.000104 #> 6 enrolled_univ… factor 386 2.01 4 0.000209 #> 7 education_lev… ordered 460 2.40 6 0.000313 #> 8 major_discipl… factor 2813 14.7 7 0.000365 #> 9 experience ordered 65 0.339 23 0.00120 #> 10 company_size ordered 5938 31.0 9 0.000470 #> 11 company_type factor 6140 32.0 7 0.000365 #> 12 last_new_job ordered 423 2.21 7 0.000365 #> 13 training_hours integer 0 0 241 0.0126 #> 14 job_chnge factor 0 0 2 0.000104
# Select the variable to diagnose diagnose(jobchange, gender, experience, training_hours)
#> # A tibble: 3 x 6 #> variables types missing_count missing_percent unique_count unique_rate #> <chr> <chr> <int> <dbl> <int> <dbl> #> 1 gender factor 4508 23.5 4 0.000209 #> 2 experience ordered 65 0.339 23 0.00120 #> 3 training_hours integer 0 0 241 0.0126
diagnose(jobchange, -gender, -experience, -training_hours)
#> # A tibble: 11 x 6 #> variables types missing_count missing_percent unique_count unique_rate #> <chr> <chr> <int> <dbl> <int> <dbl> #> 1 enrollee_id charac… 0 0 19158 1 #> 2 city factor 0 0 123 0.00642 #> 3 city_dev_index numeric 0 0 93 0.00485 #> 4 relevent_expe… factor 0 0 2 0.000104 #> 5 enrolled_univ… factor 386 2.01 4 0.000209 #> 6 education_lev… ordered 460 2.40 6 0.000313 #> 7 major_discipl… factor 2813 14.7 7 0.000365 #> 8 company_size ordered 5938 31.0 9 0.000470 #> 9 company_type factor 6140 32.0 7 0.000365 #> 10 last_new_job ordered 423 2.21 7 0.000365 #> 11 job_chnge factor 0 0 2 0.000104
diagnose(jobchange, "gender", "experience", "training_hours")
#> # A tibble: 3 x 6 #> variables types missing_count missing_percent unique_count unique_rate #> <chr> <chr> <int> <dbl> <int> <dbl> #> 1 gender factor 4508 23.5 4 0.000209 #> 2 experience ordered 65 0.339 23 0.00120 #> 3 training_hours integer 0 0 241 0.0126
diagnose(jobchange, 4, 9, 13)
#> # A tibble: 3 x 6 #> variables types missing_count missing_percent unique_count unique_rate #> <chr> <chr> <int> <dbl> <int> <dbl> #> 1 gender factor 4508 23.5 4 0.000209 #> 2 experience ordered 65 0.339 23 0.00120 #> 3 training_hours integer 0 0 241 0.0126
# Using pipes --------------------------------- library(dplyr) # Diagnosis of all variables jobchange %>% diagnose()
#> # A tibble: 14 x 6 #> variables types missing_count missing_percent unique_count unique_rate #> <chr> <chr> <int> <dbl> <int> <dbl> #> 1 enrollee_id charac… 0 0 19158 1 #> 2 city factor 0 0 123 0.00642 #> 3 city_dev_index numeric 0 0 93 0.00485 #> 4 gender factor 4508 23.5 4 0.000209 #> 5 relevent_expe… factor 0 0 2 0.000104 #> 6 enrolled_univ… factor 386 2.01 4 0.000209 #> 7 education_lev… ordered 460 2.40 6 0.000313 #> 8 major_discipl… factor 2813 14.7 7 0.000365 #> 9 experience ordered 65 0.339 23 0.00120 #> 10 company_size ordered 5938 31.0 9 0.000470 #> 11 company_type factor 6140 32.0 7 0.000365 #> 12 last_new_job ordered 423 2.21 7 0.000365 #> 13 training_hours integer 0 0 241 0.0126 #> 14 job_chnge factor 0 0 2 0.000104
# Positive values select variables jobchange %>% diagnose(gender, experience, training_hours)
#> # A tibble: 3 x 6 #> variables types missing_count missing_percent unique_count unique_rate #> <chr> <chr> <int> <dbl> <int> <dbl> #> 1 gender factor 4508 23.5 4 0.000209 #> 2 experience ordered 65 0.339 23 0.00120 #> 3 training_hours integer 0 0 241 0.0126
# Negative values to drop variables jobchange %>% diagnose(-gender, -experience, -training_hours)
#> # A tibble: 11 x 6 #> variables types missing_count missing_percent unique_count unique_rate #> <chr> <chr> <int> <dbl> <int> <dbl> #> 1 enrollee_id charac… 0 0 19158 1 #> 2 city factor 0 0 123 0.00642 #> 3 city_dev_index numeric 0 0 93 0.00485 #> 4 relevent_expe… factor 0 0 2 0.000104 #> 5 enrolled_univ… factor 386 2.01 4 0.000209 #> 6 education_lev… ordered 460 2.40 6 0.000313 #> 7 major_discipl… factor 2813 14.7 7 0.000365 #> 8 company_size ordered 5938 31.0 9 0.000470 #> 9 company_type factor 6140 32.0 7 0.000365 #> 10 last_new_job ordered 423 2.21 7 0.000365 #> 11 job_chnge factor 0 0 2 0.000104
# Positions values select variables jobchange %>% diagnose(4, 9, 13)
#> # A tibble: 3 x 6 #> variables types missing_count missing_percent unique_count unique_rate #> <chr> <chr> <int> <dbl> <int> <dbl> #> 1 gender factor 4508 23.5 4 0.000209 #> 2 experience ordered 65 0.339 23 0.00120 #> 3 training_hours integer 0 0 241 0.0126
# Negative values to drop variables jobchange %>% diagnose(-8, -9, -10)
#> # A tibble: 11 x 6 #> variables types missing_count missing_percent unique_count unique_rate #> <chr> <chr> <int> <dbl> <int> <dbl> #> 1 enrollee_id charac… 0 0 19158 1 #> 2 city factor 0 0 123 0.00642 #> 3 city_dev_index numeric 0 0 93 0.00485 #> 4 gender factor 4508 23.5 4 0.000209 #> 5 relevent_expe… factor 0 0 2 0.000104 #> 6 enrolled_univ… factor 386 2.01 4 0.000209 #> 7 education_lev… ordered 460 2.40 6 0.000313 #> 8 company_type factor 6140 32.0 7 0.000365 #> 9 last_new_job ordered 423 2.21 7 0.000365 #> 10 training_hours integer 0 0 241 0.0126 #> 11 job_chnge factor 0 0 2 0.000104
# Using pipes & dplyr ------------------------- # Diagnosis of missing variables jobchange %>% diagnose() %>% filter(missing_count > 0)
#> # A tibble: 8 x 6 #> variables types missing_count missing_percent unique_count unique_rate #> <chr> <chr> <int> <dbl> <int> <dbl> #> 1 gender factor 4508 23.5 4 0.000209 #> 2 enrolled_univer… factor 386 2.01 4 0.000209 #> 3 education_level order… 460 2.40 6 0.000313 #> 4 major_discipline factor 2813 14.7 7 0.000365 #> 5 experience order… 65 0.339 23 0.00120 #> 6 company_size order… 5938 31.0 9 0.000470 #> 7 company_type factor 6140 32.0 7 0.000365 #> 8 last_new_job order… 423 2.21 7 0.000365
# }