title: R - How to one hot encoding a single column while keep other columns still?
body: <p>I have a data frame like this:</p>
  
  <pre><code>group   student exam_passed subject 
  A       01      Y           Math
  A       01      N           Science
  A       01      Y           Japanese
  A       02      N           Math
  A       02      Y           Science
  B       01      Y           Japanese
  C       02      N           Math
  </code></pre>
  
  <p>What I would like to achieve is the below result:</p>
  
  <pre><code>group   student exam_passed subject_Math  subject_Science  subject_Japanese   
  A       01      Y           1             0                0
  A       01      N           0             1                0
  A       01      Y           0             0                1
  A       02      N           1             0                0           
  A       02      Y           0             1                0
  B       01      Y           0             0                1
  C       02      N           1             0                0
  </code></pre>
  
  <p>Here is the test data frame:</p>
  
  <pre><code>df &lt;- data.frame(
  group = c('A', 'A', 'A', 'A', 'A', 'B', 'C'),
  student = c('01', '01', '01', '02', '02', '01', '02'),
  exam_pass = c('Y', 'N', 'Y', 'N', 'Y', 'Y', 'N'),
  subject = c('Math', 'Science', 'Japanese', 'Math', 'Science', 'Japanese', 'Math')
  )
  </code></pre>
  
  <p>I have tried for loop, however, the original data is too large to deal with, and </p>
  
  <pre><code>mltools::one_hot(df, col = 'subject')
  </code></pre>
  
  <p>doesn't work either because of the this error:</p>
  
  <pre><code>Error in `[.data.frame`(dt, , cols, with = FALSE) :
  unused argument (with = FALSE)
  </code></pre>
  
  <p>Could anyone help me with this? Thanks!</p>