diagnose.tbl_dbi | R Documentation |
The diagnose() produces information for diagnosing the quality of the column of the DBMS table through tbl_dbi.
## S3 method for class 'tbl_dbi'
diagnose(.data, ..., in_database = TRUE, collect_size = Inf)
.data |
a tbl_dbi. |
... |
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. |
in_database |
a logical. Specifies whether to perform in-database operations. If TRUE, most operations are performed in the DBMS. if FALSE, table data is taken in R and operated in-memory. |
collect_size |
a integer. The number of data samples from the DBMS to R. Applies only if in_database = FALSE. |
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. You can use grouped_df as the group_by() function.
An object of tbl_df.
The information derived from the data diagnosis is as follows.:
variables : column 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.
diagnose.data.frame
, diagnose_category.tbl_dbi
, diagnose_numeric.tbl_dbi
.
library(dplyr)
if (requireNamespace("DBI", quietly = TRUE) & requireNamespace("RSQLite", quietly = TRUE)) {
# connect DBMS
con_sqlite <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
# copy jobchange to the DBMS with a table named TB_JOBCHANGE
copy_to(con_sqlite, jobchange, name = "TB_JOBCHANGE", overwrite = TRUE)
# Using pipes ---------------------------------
# Diagnosis of all columns
con_sqlite %>%
tbl("TB_JOBCHANGE") %>%
diagnose() %>%
print()
# Positions values select columns, and In-memory mode and collect size is 200
con_sqlite %>%
tbl("TB_JOBCHANGE") %>%
diagnose(gender, education_level, company_size, in_database = FALSE, collect_size = 200) %>%
print()
# Using pipes & dplyr -------------------------
# Diagnosis of missing variables
con_sqlite %>%
tbl("TB_JOBCHANGE") %>%
diagnose() %>%
filter(missing_count > 0) %>%
print()
# Using pipes & dplyr -------------------------
# Diagnosis of missing variables
con_sqlite %>%
tbl("TB_JOBCHANGE") %>%
group_by(job_chnge) %>%
diagnose() %>%
print()
# Disconnect DBMS
DBI::dbDisconnect(con_sqlite)
} else {
cat("If you want to use this feature, you need to install the 'DBI' and 'RSQLite' package.\n")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.