Skip to content

Instantly share code, notes, and snippets.

@tengpeng
Created February 2, 2016 20:50
Show Gist options
  • Save tengpeng/91a00ead7d25846667f0 to your computer and use it in GitHub Desktop.
Save tengpeng/91a00ead7d25846667f0 to your computer and use it in GitHub Desktop.
categorical to numerical
## Convert categorical features into numerical features ##
for (f in common_vars) {
if (class(train[[f]]) == "character"){
levels <- unique(c(train[[f]], test[[f]]))
train[[f]] <- as.integer(factor(train[[f]], levels=levels))
test[[f]] <- as.integer(factor(test[[f]], levels=levels))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment