Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. #' One-hot encode categorical variables.
  2. #'
  3. #' This function one-hot encodes categorical variables and binds the entire frame.
  4. #'
  5. #' @param data frame
  6. #' @param feature to encode
  7. #' @return hot-encoded data frame
  8. #'
  9. #' @export
  10. encode_and_bind <- function(frame, feature_to_encode) {
  11. res <- cbind(iris, one_hot(as.data.table(frame[[feature_to_encode]])))
  12. return(res)
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement