Assume I have a dataframe with one column of class “Date” in R:
Date Sales Type
1 2012-03-22 22 A
2 2012-03-22 18 B
3 2012-04-11 20 C
4 2012-05-03 26 A
5 2012-05-03 15 C
6 2012-06-12 29 A
7 2012-07-15 22 B
I want to create dummy variables for certain groupings of months in order to run various linear and glm models. For instance, if I form 3 groups consisting of months {3}, {5} and {6,7} respectively, I want 3 dummy variables, call them Dummy1, Dummy2 and Dummy3 respectively to get the following table:
Date Sales Type Dummy1 Dummy2 Dummy3
1 2012-03-22 22 A 1 0 0
2 2012-03-22 18 B 1 0 0
3 2012-04-11 20 C 0 0 0
4 2012-05-03 26 A 0 1 0
5 2012-05-03 15 C 0 1 0
6 2012-06-12 29 A 0 0 1
7 2012-07-15 22 B 0 0 1
How can I achieve this?