0

I am wondering if there is a built in command in R that would replicate the pd.get_dummies() function in python.

What this does is, for example I have a data set T

Chris     Male
Mary      Female
Bob       Male
John      Male

I want it to convert these unique categories (Male and Female) into binary data, such as having it show as

         Male     Female
Chris     1          0
Mary      0          1
Bob       1          0
John      1          0

Would anyone be able to shine some light on this? I would like to know the function and package that would need to be applied. If there does not exist one, how would you convert it?

TFchris
  • 33
  • 3

1 Answers1

0

Never mind, I figured it out.

model.matrix(~dataset)

works just fine.

A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485
TFchris
  • 33
  • 3