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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With