These functions decide and report if a single variable represented by a single instance of an `Hmisc`'s [describe][Hmisc::describe] object will considered a categorical variable or a continuous one.
htype(x, n_unique = 10L)
htypes(x, n_unique = 10L)
# S3 method for describe
htypes(x, n_unique = 10L)
# S3 method for default
htypes(x, n_unique = 10L)
is_hcat(x)
is_hcon(x, n_unique = 10L)
an instance of the class [describe][Hmisc::describe], in the cases of "singular" functions (ie `is_*()` or `htype()`) it must be a single-variable [describe][Hmisc::describe] object.
(int, 10L) the minimum number of distinct values a numeric variable must have before plot.describe uses it in a continuous variable plot.
(chr) `htype` returns one of "cat" (if `x` will be considered categorical), "con" (if `x` will be considered continuous), "none" (if `x` will be not considered categorical nor continuous, and hence it will be not plotted), or "both" (with a warning, if the variable will be considered both categorical and continuous. This would possibly never happen).
(chr) character vector of the types identified by [htype] for every variable represented in (each element of) `x`.
(lgl) `is_hcat` returns TRUE if x will be considered categorical.
(lgl) `is_hcon` returns TRUE if x will be considered continuous.
A "single" object of `Hmisc`'s [describe][Hmisc::describe] class represents a variable. When you plot and object of class [describe][Hmisc::describe] the plot function decide if it is a continuous variable or a categorical one to plot it in the correspond plot. It is also possible that the variable is not considered in none of that categories, in which case it will not be plotted at all.
These functions have been produced/deduced from reading the source code of `Hmisc`'s [plot][Hmisc::describe]. In particular, from the definition of the (two distinct) functions `f` defined within it (one for categorical variables and the other for continuous variables). Both lead to a possible execution of `warning("no categorical variable found")` or `warning("no continuous variable found")`. I tried to keep the same names/code/logic that I found there.
htypes()
: Report types for multi-variables objects
is_hcat()
: Check if a single-instance of a
[describe][Hmisc::describe] object is categorical.
is_hcon()
: Check if a single-instance of a
[describe][Hmisc::describe] object is continuous.
[describe][Hmisc::describe],
[is_hdesc], [is_single_hdesc]
Gist with test and usage examples: https://bit.ly/htype-gist
# \donttest{
library(Hmisc)
desc <- describe(mtcars)
htype(desc[["vs"]]) # "cat"
#> [1] "cat"
htype(desc[["mpg"]]) # "con"
#> [1] "con"
htype(desc[["cyl"]]) # "none"
#> [1] "none"
# }
# \donttest{
htypes(desc) # c(
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> "con" "none" "con" "con" "con" "con" "con" "cat" "cat" "none" "none"
# mpg = "con", cyl = "none", disp = "con",
# hp = "con", drat = "con", wt = "con", qsec = "con",
# vs = "cat", am = "cat", gear = "none",
# carb = "none"
# )
# }
# \donttest{
htypes(mtcars) # htypes(desc)
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> "con" "none" "con" "con" "con" "con" "con" "cat" "cat" "none" "none"
htypes(letters) # "none"
#> [1] "none"
# }
# \donttest{
is_hcat(desc[["vs"]]) # TRUE
#> [1] TRUE
is_hcat(desc[["mpg"]]) # FALSE
#> [1] FALSE
# }
# \donttest{
is_hcon(desc[["vs"]]) # FALSE
#> [1] FALSE
is_hcon(desc[["mpg"]]) # TRUE
#> [1] TRUE
# }