How does ggplot
identify if a variable is continuous or discrete?
I am writing a function to identify it but ggplot
does it well.
What does the function that accomplishes this in ggplot
look like?
I am trying to write general function, where we provide just dataframe and function should approximate what variables are discrete and what are continuous...
My basic function looks like this we provide Dataframe and maximum number of unique values
Classify_numeric <- function(DF = DATA, n_unique) {
for (i in 1:ncol(DF)) {
if (is.numeric(DF[ , i])) {
print(colnames(DF)[i])
if (length(unique(DF[ ,i])) <= n_unique) {print("Discrete")}
else {print("Continuous")}
}
}
}
Classify_numeric(A, n_unique = 30) # this parameter can be change to whatever or we can
# write it that n_unique can be some % of lenght of Dataframe
and same function just with is.factor
function
Classify_factor <- function(DF = DATA, n_unique) {
for (i in 1:ncol(DF)) {
if (is.factor(DF[ , i])) {
print(colnames(DF)[i])
if (length(unique(DF[ ,i])) <= n_unique) {print("Klasifikovatelny")}
else {print("NEklasifikovatelny")}
}
}
}
Classify_factor(A, n_unique = 20)