0

I have seen this asked elsewhere, but I cannot figure out how to implement so my situation.

I have a data frame with 30 variables. Two of the variables are factors that have over 100 levels. I am doing a RandomForest, so I need to convert 1 variable with 100 factors to 100 dummies variables.

Normally I use the iflse to create dummy, but do not want to code 100 new variables manually.

My variable is Car$Model (a factor with 100 levels).

I want some like this created and inserted into the dataframe with a 1/0:

Car$Model1
Car$Model2
Car$Model3
...
Car$Model100

mpg
  • 3,679
  • 8
  • 36
  • 45
  • 1
    what are other variable , can you atleast give us some reproducible example. `cast(df, ...~yourfactorvariable)` – Ananta Mar 02 '14 at 01:03
  • See http://stackoverflow.com/questions/22021988/r-create-a-1-0-t-f-contrast-like-matrix-new-variable-based-on-column-value/22022154#22022154 or the `dummies` package – Jake Burkhead Mar 02 '14 at 01:19

0 Answers0