diagnose_category | R Documentation |
The diagnose_category() produces information for diagnosing the quality of the variables of data.frame or tbl_df.
diagnose_category(.data, ...)
## S3 method for class 'data.frame'
diagnose_category(
.data,
...,
top = 10,
type = c("rank", "n")[2],
add_character = TRUE,
add_date = TRUE
)
## S3 method for class 'grouped_df'
diagnose_category(
.data,
...,
top = 10,
type = c("rank", "n")[2],
add_character = TRUE,
add_date = TRUE
)
.data |
a data.frame or a |
... |
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_category() 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. |
top |
an integer. Specifies the upper top rows or rank to extract. Default is 10. |
type |
a character string specifying how result are extracted. "rank" that extract top n ranks by decreasing frequency. In this case, if there are ties in rank, more rows than the number specified by the top argument are returned. Default is "n" extract only top n rows by decreasing frequency. If there are too many rows to be returned because there are too many ties, you can adjust the returned rows appropriately by using "n". |
add_character |
logical. Decide whether to include text variables in the diagnosis of categorical data. The default value is TRUE, which also includes character variables. |
add_date |
ogical. Decide whether to include Date and POSIXct variables in the diagnosis of categorical data. The default value is TRUE, which also includes character variables. |
The scope of the diagnosis is the occupancy status of the levels in categorical data. If a certain level of occupancy is close to 100 then the removal of this variable in the forecast model will have to be considered. Also, if the occupancy of all levels is close to 0 variable is likely to be an identifier.
an object of tbl_df.
The information derived from the categorical data diagnosis is as follows.
variables : variable names
levels: level names
N : number of observation
freq : number of observation at the levels
ratio : percentage of observation at the levels
rank : rank of occupancy ratio of levels
See vignette("diagonosis") for an introduction to these concepts.
diagnose_category.tbl_dbi
, diagnose.data.frame
, diagnose_numeric.data.frame
, diagnose_outlier.data.frame
.
# Diagnosis of categorical variables
diagnose_category(jobchange)
# Select the variable to diagnose
diagnose_category(jobchange, education_level, company_type)
# Using pipes ---------------------------------
library(dplyr)
# Diagnosis of all categorical variables
jobchange %>%
diagnose_category()
# Positive values select variables
jobchange %>%
diagnose_category(company_type, job_chnge)
# Negative values to drop variables
jobchange %>%
diagnose_category(-company_type, -job_chnge)
# Top rank levels with top argument
jobchange %>%
diagnose_category(top = 2)
# Using pipes & dplyr -------------------------
# Extraction of level that is more than 60% of categorical data
jobchange %>%
diagnose_category() %>%
filter(ratio >= 60)
# All observations of enrollee_id have a rank of 1.
# Because it is a unique identifier. Therefore, if you select up to the top rank 3,
# all records are displayed. It will probably fill your screen.
# extract rows that less than equal rank 3
# default of type argument is "n"
jobchange %>%
diagnose_category(enrollee_id, top = 3)
# extract rows that less than equal rank 3
jobchange %>%
diagnose_category(enrollee_id, top = 3, type = "rank")
# extract only 3 rows
jobchange %>%
diagnose_category(enrollee_id, top = 3, type = "n")
# Using group_by ------------------------------
# Calculate the diagnosis of 'company_type' variable by 'job_chnge' using group_by()
jobchange %>%
group_by(job_chnge) %>%
diagnose_category(company_type)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.