title: How to add dummy variables Q1, Q2, Q3 based on the month of Date variable (YYYYMMDD)?
body: <p>I want to create 4 dummy variables referring to every quarter as Q1, Q2, Q3, Q4 which would be dependent on the month of Sales which is in Date format.</p>
  
  <p>Something like this:</p>
  
  <pre><code>Date         Q1 Q2 Q3 Q4
  01/01/2017    1  0  0  0
  02/01/2017    0  1  0  0
  03/01/2017    0  0  1  0
  04/01/2017    0  0  0  1
  </code></pre>
  
  <p>I tried extracting the month of Sales date using month(Date) using lubridate package and then tried to create dummy variables, Q1, Q2, Q3, Q4 on these lines (not exactly the same code but trying to use this logic to created variables): </p>
  
  <pre><code>df$Q1 &lt;- ifelse(month(Date) = *"first month of every quarter"*,1,0)
  df$Q2 &lt;- ifelse(month(Date) = *"second month of every quarter"*,1,0)
  df$Q3 &lt;- ifelse(month(Date) = *"third month of every quarter"*,1,0)  
  df$Q4 &lt;- ifelse(month(Date) = *"fourth month of every quarter"*,1,0)  
  </code></pre>
  
  <p>But this method didn't work to get a matrix like mentioned above.</p>
  
  <p>Please help with the same or if there is some smarter way to accomplish this then please let me know.</p>