Determine type/class of a variable

variable_type(.var)

Arguments

.var

A vector, data frame column, or equivalent.

Value

One of "factor", "character", "numeric", "logical", "date".

Examples

var_d = as.Date("12.03.18", "%d.%m.%y") var_f = factor(c("yes", "no")) var_c = c("yes", "no") var_n = 1:10 var_l = as.logical(c("true", "false")) variable_type(var_d)
#> [1] "date"
variable_type(var_f)
#> [1] "factor"
variable_type(var_c)
#> [1] "character"
variable_type(var_n)
#> [1] "numeric"
variable_type(var_l)
#> [1] "logical"