1
$\begingroup$

For building a machine learning model I used dummyVars() function to create the dummy variables for building a model.

dummies_model <- dummyVars(" ~ .", data=input_data)
input_data2 <- predict(dummies_model, input_data)

I am now deploying the model but I want to return to the user the table with the original columns (not the factor columns). Is there a function that returns the original columns and not the dummy ones created by dummyVars()?

$\endgroup$

closed as off-topic by whuber Feb 7 at 13:59

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – whuber
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ This link will provide the answer: amunategui.github.io/dummyVar-Walkthrough. In essence, just doing something like data.frame(input_data2) should work. Try print(data.frame(input_data2)) to print the dummies in the R console. $\endgroup$ – Isabella Ghement Feb 7 at 15:09
  • $\begingroup$ Not sure if I was clear or did not understand your answer. I already have the model with dummies. Now I want to return to the original columns of the dataset, for example sex: male and female, turned into two binary columns: male and female, now I want to go back to having one column with a factor of two levels. $\endgroup$ – Fernando Han Feb 8 at 17:57
  • $\begingroup$ Don't you have that information in your input_data? That's where you would find your original variables. $\endgroup$ – Isabella Ghement Feb 8 at 18:24
  • $\begingroup$ Yes I do, but since some of the observations are removed, either because of NA, outliers etc, I would not be able to use the original input data if I don't have a unique row identifier. $\endgroup$ – Fernando Han Feb 9 at 16:26