Skip to content

Instantly share code, notes, and snippets.

@thoolihan
Created October 22, 2019 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thoolihan/acd7db30f7ee5e852234f179aa1cc9d9 to your computer and use it in GitHub Desktop.
Save thoolihan/acd7db30f7ee5e852234f179aa1cc9d9 to your computer and use it in GitHub Desktop.
creating ordinal numbers
# casting as integer
int_cyl <- as.integer(mtcars$cyl)
int_cyl
# creating a factor
factor_cyl <- as.factor(mtcars$cyl)
factor_cyl
# flag columns / dummy variables
library(caret)
trans <- dummyVars(~ as.factor(cyl), data=mtcars)
predict(trans, mtcars)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment