Go to TogaWare.com Home Page. Data Science Desktop Survival Guide
by Graham Williams
Duck Duck Go



CLICK HERE TO VISIT THE UPDATED SURVIVAL GUIDE

Identify Numeric and Categoric Variables

20180726 Identifying numeric and categoric variables may be useful for example for cluster analysis algorithms that only deal with numeric variables. Here we identify them by name (a character string) and by index. When using the index we have to assume the variables remain in the same order within the dataset and all variables are present, otherwise the indicies will get out of sync.

# Identify the numeric variables by index.

ds %>%
  sapply(is.numeric) %>%
  which() %>%
  intersect(inputi) %T>%
  print() ->
numi
##  [1]  3  4  5  6  7  9 12 13 14 15 16 18 19

# Identify the numeric variables by name.

ds %>%
  names() %>%
  extract(numi) %T>%
  print() ->
numc
##  [1] "min_temp"        "max_temp"        "rainfall"        "evaporation"...
##  [5] "sunshine"        "wind_gust_speed" "wind_speed_9am"  "wind_speed_3...
##  [9] "humidity_9am"    "humidity_3pm"    "pressure_9am"    "cloud_9am"  ...
## [13] "cloud_3pm"

# Identify the categoric variables by index and then name.

ds %>%
  sapply(is.factor) %>%
  which() %>%
  intersect(inputi) %T>%
  print() ->
cati
## [1]  8 10 11 22

ds %>%
  names() %>%
  extract(cati) %T>%
  print() ->
catc
## [1] "wind_gust_dir" "wind_dir_9am"  "wind_dir_3pm"  "rain_today"


Support further development by purchasing the PDF version of the book.
Other online resources include the GNU/Linux Desktop Survival Guide.
Books available on Amazon include Data Mining with Rattle and Essentials of Data Science.
Popular open source software includes rattle and wajig.
Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 2000-2020 Togaware Pty Ltd. . Creative Commons ShareAlike V4.