Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

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.

like image 940
user3619169 Avatar asked Dec 09 '22 07:12

user3619169


1 Answers

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.

like image 103
James Avatar answered Jun 07 '23 16:06

James