title: How can I one-hot encode my dataset with several categorical variables in R?
body: <p>Does anyone know how I can better clean up this data so I can run a logistic regression on it?</p>
  
  <p>I am trying to one-hot encode the variables with multiple categories like race, workclass, etc (as shown in the sample dataset below), but not sure how to do so.</p>
  
  <p>I was planning to change the income to 1 and 0 since there is only 2 categories but I cannot do the same for the rest. </p>
  
  <p>My current plan is to run a logistic regression with all the listed variables:</p>
  
  <pre><code>data &lt;- read.csv("adult_income.csv")
  mylogit &lt;- glm(formula = income ~ age + workclass + educaitonal-num + 
                     martial status + occupation + race + gender + 
                     capital-gain + capital-loss + hours-per-week + 
                     native-country, data = data, family = "binomial")
  </code></pre>
  
  <p>Sample dataset:
  <a href="https://i.stack.imgur.com/rj6ag.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rj6ag.png" alt="1"></a></p>
  
  <p>I am still fairly new to R so I apologize for any rookie mistake!</p>