In a large data set, identify which variables are categorical and which are numeric

r

Solution

You can use `split` with `sapply` to group the variables together:

split(names(iris),sapply(iris, function(x) paste(class(x), collapse=" ")))
$factor
[1] "Species"

$numeric
[1] "Sepal.Length" "Sepal.Width"  "Petal.Length" "Petal.Width"

Note the use of `paste` to collapse together any multi-class object's class names.

Problem

I have a list of 65 variables, and I want to separate out the lists of numerical and categorical variable. What can be command for this task.

Original source