The find_class() extracts variable information having a certain class from an object inheriting data.frame.
find_class(
df,
type = c("numerical", "categorical", "categorical2", "date_categorical",
"date_categorical2"),
index = TRUE
)
a data.frame or objects inheriting from data.frame
character. Defines a group of classes to be searched. "numerical" searches for "numeric" and "integer" classes, "categorical" searches for "factor" and "ordered" classes. "categorical2" adds "character" class to "categorical". "date_categorical" adds result of "categorical2" and "Date", "POSIXct". "date_categorical2" adds result of "categorical" and "Date", "POSIXct".
logical. If TRUE is return numeric vector that is variables index. and if FALSE is return character vector that is variables name. default is TRUE.
character vector or numeric vector. The meaning of vector according to data type is as follows.
character vector : variables name
numeric vector : variables index
# data.frame
find_class(iris, "numerical")
#> [1] 1 2 3 4
find_class(iris, "numerical", index = FALSE)
#> [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
find_class(iris, "categorical")
#> [1] 5
find_class(iris, "categorical", index = FALSE)
#> [1] "Species"
# tbl_df
find_class(ggplot2::diamonds, "numerical")
#> [1] 1 5 6 7 8 9 10
find_class(ggplot2::diamonds, "numerical", index = FALSE)
#> [1] "carat" "depth" "table" "price" "x" "y" "z"
find_class(ggplot2::diamonds, "categorical")
#> [1] 2 3 4
find_class(ggplot2::diamonds, "categorical", index = FALSE)
#> [1] "cut" "color" "clarity"
# type is "categorical2"
iris2 <- data.frame(iris, char = "chars",
stringsAsFactors = FALSE)
find_class(iris2, "categorical", index = FALSE)
#> [1] "Species"
find_class(iris2, "categorical2", index = FALSE)
#> [1] "Species" "char"